草庐IT

datetime_select

全部标签

c# - 如何将波斯日历日期字符串转换为 DateTime?

我使用这些代码来转换当前日期时间并将其减去用户在文本框中键入的日期时间。但是它在转换时会出错。PersianCalendarp=newSystem.Globalization.PersianCalendar();DateTimedate=newDateTime();date=DateTime.Parse(DateTime.Now.ToShortDateString());intyear=p.GetYear(date);intmonth=p.GetMonth(date);intday=p.GetDayOfMonth(date);stringstr=string.Format("{0}/{

c# - LINQ 计算 SortedList<dateTime,double> 的移动平均值

我有一个SortedList形式的时间序列.我想计算这个系列的移动平均值。我可以使用简单的for循环来做到这一点。我想知道是否有更好的方法使用linq来执行此操作。我的版本:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){varmySeries=newSortedList();mySeries.Add(newDateTime(2011,01

c# - 在 C# 中将 LDAP AccountExpires 转换为 DateTime

我想将18位字符串从LDAPAccountExpires转换为正常日期时间格式。129508380000000000>>2011年5月26日我使用以下链接获得了上述转换。http://www.chrisnowell.com/information_security_tools/date_converter/Windows_active_directory_date_converter.asp?pwdLastSet,%20accountExpires,%20lastLogonTimestamp,%20lastLogon,%20and%20badPasswordTime我尝试使用DateT

c# - 将 DateTime 转换为指定格式

我有这个日期格式yy/MM/ddHH:mm:ss例如:12/02/2110:56:09。问题是,当我尝试使用此代码将其转换为不同格式时:CDate("12/02/2110:56:09").ToString("MMM.dd,yyyyHH:mm:ss")它显示Dec。2021年12日10:56:09。我如何正确地将其格式化为:Feb.21,201210:56:09?当我从基于SMS的应用程序查询余额时返回此格式。 最佳答案 使用DateTime.ParseExact,例如:DateTime.ParseExact("12/02/2110:

c# - 将 DateTime.Now 转换为秒

我正在尝试编写一个函数,将DateTime.Now实例转换为它代表的秒数,以便我可以将其与另一个DateTime实例进行比较。这是我目前拥有的:publicstaticintconvertDateTimeToSeconds(DateTimedateTimeToConvert){intsecsInAMin=60;intsecsInAnHour=60*secsInAMin;intsecsInADay=24*secsInAnHour;doublesecsInAYear=(int)365.25*secsInADay;inttotalSeconds=(int)(dateTimeToConvert

c# - 在 LINQ Select 中赋值?

我有以下查询:drivers.Select(d=>{d.id=0;d.updated=DateTime.Now;returnd;}).ToList();drivers是一个包含不同ID和更新值的列表,因此我正在更改Select中的值,但这是执行此操作的正确方法。我已经知道我不会将驱动程序重新分配给驱动程序,因为Resharper对此有所提示,所以我想如果这样会更好:drivers=drivers.Select(d=>{d.id=0;d.updated=DateTime.Now;returnd;}).ToList();但这仍然是有人应该为驱动程序列表中的每个元素分配新值的方式吗?

c# - 为什么 Linq to Entity Select Method 翻转投影列表属性?

我对linqtoentity/Json/MVC.net4有最奇怪的行为我有这段代码,出于某种奇怪的原因,所有其他列表的属性顺序都颠倒了。varoutput=db.FooBar.Where(a=>a.lookupFoo==bar).Select(a=>newList{//value'sarethesameperrow//fordemonstrationsake.a.fooBarA,//Always12.34a.fooBarB,//Always12.34a.fooBarC,//Always0a.fooBarD//Always0//lazycastingtodoublefromint});r

c# - 更改 ASP.NET Core 中 DateTime 解析的默认格式

我在ASP.NETCoreController中得到一个日期,如下所示:publicclassMyController:Controller{publicIActionResultTest(DateTimedate){}}框架能够解析日期,但只能是英文格式。当我将04.12.2017作为日期参数传递时,我的意思是2017年12月4日。这将被解析为英语日期,因此我的日期对象获得值2017年4月12日。我尝试仅添加德语使用this文章还有this,但没有成功。要使ASP.NETCore以正确的德语格式自动解析日期,需要做什么?更新我尝试设置RequestLocalizationOption

c# - Linq order by aggregate in select { }

这是我正在处理的一个:varfStep=frominspinsq.Inspectionswhereinsp.TestTimeStamp>dStartTime&&insp.TestTimeStamp我想按所选投影中的一个或多个字段排序。 最佳答案 最简单的更改可能是使用查询延续:varfStep=frominspinsq.Inspectionswhereinsp.TestTimeStamp>dStartTime&&insp.TestTimeStamp老实说,这基本上等同于使用“let”——真正的区别在于let引入了一个新范围变量,而查

c# - Linq:TimeSpan 中 2 个 DateTime 之间的差异

我正在尝试这样做:Tickets.Where(t=>(t.Date-myTicket.Date)我收到“DbArithmeticExpression参数必须具有数字通用类型”错误。考虑到我需要TimeSpan的差异,我该怎么做?提前致谢。 最佳答案 你会想要使用SqlFunctions.DateDiffTickets.Where(t=>SqlFunctions.DateDiff("second",t.Date,myTicket.Date) 关于c#-Linq:TimeSpan中2个Dat