草庐IT

DATETIME_FORMAT

全部标签

c# - 为什么 String.Format 将正斜杠转换为减号?

为什么String.Format("/")会转换为“-”? 最佳答案 我怀疑您在{0}占位符内使用了/符号。它是在给定文化中用作日期时间分隔符的保留符号。你可以像这样逃避它:stringdate=string.Format("{0:dd\\/MM\\/yyyy}",DateTime.Now); 关于c#-为什么String.Format将正斜杠转换为减号?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

c# - string.Format() 参数

您可以向string.Format()方法传递多少个参数?一定有某种理论或强制限制。它是基于params[]类型的限制还是基于使用它的应用程序的内存使用情况或完全基于其他因素? 最佳答案 好吧,我从隐藏中出现了...我使用以下程序来验证发生了什么,而Marc指出像这样的字符串“{0}{1}{2}...{2147483647}”会在参数列表之前超过2GiB的内存限制,我的发现与你的不匹配。因此,您可以在string.Format方法调用中放入的参数数量的硬性限制必须是107713904。inti=0;longsum=0;while(s

c# - 类型 'System.DateTime' 的表达式不能用于返回类型 'System.Object'

我已经创建了一个用于排序的表达式,它工作正常,直到我点击DateTime字段,我在其中收到以下错误(在第二行):Expressionoftype'System.DateTime'cannotbeusedforreturntype'System.Object'这是我的代码:ParameterExpressionparam=Expression.Parameter(typeof(MyEntity),"x");Expression>sortExpression=Expression.Lambda>(Expression.Property(param,sortKey),param);有人能帮忙

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# - System.BadImageFormatException :Could not load file or assembly … incorrect format when trying to install service with installutil. 可执行文件

我知道我要问duplicate问题,但我的情况完全不同,我认为是因为当我使用程序的nunit工具进行单元测试时,在NUnit中会发生此错误”NewTest.test测试(TestFixtureSetUp):设置:System.BadImageFormatException:无法加载文件或程序集“AUTO_REPAIR,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。试图加载格式不正确的程序。”我想知道为什么这个工具会出现这个错误?我确信我在项目或任何测试用例中都没有错误。请帮帮我。这是这个错误的图片

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