草庐IT

datetime2

全部标签

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# - 更改 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: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

c# - 将泛型方法中的 T 参数转换为 DateTime

我有以下(简化的)方法:privatestaticstringGetStringFromValue(Tval){if(typeof(T)==typeof(DateTime)){returnstring.Format("{0}",((DateTime)val).Year.ToString("0000"));}returnstring.Empty;}在强制转换“(DateTime)val”时出现以下错误:CannotcastexpressionofType'T'totype'DateTime'如何访问DateTime参数的Year属性?更新:感谢您所有快速的答复。这个方法(和方法名称)真的

C#,NUnit : Is it possible to test that a DateTime is very close, 但不一定等于另一个?

假设我有这个测试:[Test]publicvoidSomeTest(){varmessage=newThing("foobar");Assert.That(thing.Created,Is.EqualTo(DateTime.Now));}例如,这可能会使Thing的构造函数失败,这会花费一些时间。是否有某种NUnit构造允许我指定Created时间不必完全等于DateTime.Now,只要它在一秒之内?是的,我知道构造函数不应该花费太多时间,但只是作为一个例子:p 最佳答案 没试过,但根据thedocs看起来这应该可行:Assert

c# - null 和 datetime 之间没有隐式转换

这个问题在这里已经有了答案:ConditionaloperatorassignmentwithNullabletypes?(6个答案)关闭9年前。以下代码从给定的DataRow(modelValue)读取一段数据并将其解析为nullableDateTime实例。问题:请参阅L1和L2下的代码部分,两者在技术上是相等的(如果我没有犯任何小学生错误)。但是,L1按预期工作,但不是L2。我得到了thereisnoimplicitconversionbetweennullanddatetime当我执行L2下的代码时。有人可以给我建议吗?DateTime?CallBack;varcallBack

C# 在使用反射时确定一个 Nullable 属性 DateTime 类型

我有一个关于如何确定对象的Nullable属性类型的问题。ObjectA有一个属性DateTime?创建日期;当我像下面的代码一样遍历其属性时,如何检查属性是否为NullableDateTime类型?foreach(PropertyInfopiinObjectA.GetType().GetProperties()){//dothecomparehere} 最佳答案 pi.PropertyType==typeof(DateTime?) 关于C#在使用反射时确定一个Nullable属性Dat