草庐IT

datetime-parsing

全部标签

c# - LINQ to Entities 无法识别方法 'Int32 Parse(System.String)' 方法,并且无法将此方法翻译成存储表达式

我正在使用EntityFramework,我有一行代码将var转换回数据库的iint。varrecord=context.enrollments.SingleOrDefault(row=>row.userId==int.Parse(UserID)&&row.classId==int.Parse(ClassID));每当我尝试运行它时,我都会收到rhis错误。“LINQtoEntities无法识别‘Int32Parse(System.String)’方法,并且无法将此方法转换为存储表达式。”我也试过varrecord=context.enrollments.FirstOrDefault(

c# - 如何使用 DateTime.Parse() 创建 DateTime 对象

如果我有一个格式为yyyyMMddHHmmssfff的字符串,例如20110815174346225。我将如何从该字符串创建DateTime对象。我尝试了以下DateTimeTimeStamp=DateTime.Parse(Data[1],"yyyyMMddHHmmssfff");但是我得到了这些错误:Error1Thebestoverloadedmethodmatchfor'System.DateTime.Parse(string,System.IFormatProvider)'hassomeinvalidargumentsC:\DocumentsandSettings\rkelly

c# - 在 .NET 中使用字符串格式 "M"发出 DateTime.ToString

我对DateTime的字符串格式有疑问。我认为这是MS中的错误。你能解释一下吗?有什么问题吗?classProgram{staticvoidMain(string[]args){Console.WriteLine(DateTime.Now.ToString("M"));//return07JulyMSDN 最佳答案 来自The"M"CustomFormatSpecifierIfthe"M"formatspecifierisusedwithoutothercustomformatspecifiers,itisinterpretedas

C# DateTime ToString ("MM-dd-yyyy") 返回有趣的日期值

我在ASP.Net页面的代码隐藏文件中有以下代码txtStartDate.Text=DateTime.Today.ToString("MM-dd-yyyy");我希望返回“09-11-2009”。但是,当我在开发服务器上运行该页面时,我在文本框中看到“09-00-2009”。我看不出有任何原因,所以我显然遗漏了一些东西。有人知道吗? 最佳答案 我不明白为什么它会显示00,但作为一个随机建议,您可以尝试:...=DateTime.Today.ToString("MM-dd-yyyy",CultureInfo.InvariantCult

c# - 如何测试 DateTime 是否在一周的 2 天之间(DayOfWeek)

在C#中,给定一组任意的DayOfWeek端点(例如DayOfWeek.Friday和DayOfWeek.Sunday)如何测试任意日期是否介于这两天之间(含)?例子://result==true;Oct23,2010isaSaturdayvarresult=InBetweenDaysInclusive(newDateTime(2010,10,23),DayOfWeek.Friday,DayOfWeek.Sunday);//result==true;Oct22,2010isaFridayresult=InBetweenDaysInclusive(newDateTime(2010,10,

c# - Enum.Parse() 或 Switch

对于将字符串转换为枚举,以下哪种方式更好?这段代码:colorEnumcolor=(colorEnum)Enum.Parse(typeof(colorEnum),"Green");或者这个:stringcolorString=...colorEnumcolor;switch(colorString){case"Green":color=colorEnum.Green;break;case"Red":color=colorEnum.Red;break;case"Orange":color=colorEnum.Orange;break;....} 最佳答案

c# - 使用 C# 从 DateTime 获取日期

愚蠢的问题。给定日期时间中的日期,我知道它是星期二,例如我怎么知道它的tue=2和mon=1等...谢谢 最佳答案 您正在寻找DayOfWeek属性(property)。然后,正如Dan在下面的评论中建议的那样,只需查看枚举的整数值即可将日期作为整数获取:intd=(int)System.DateTime.Now.DayOfWeek 关于c#-使用C#从DateTime获取日期,我们在StackOverflow上找到一个类似的问题: https://stack

c# - 如何在 C# 中将参数默认为 DateTime.MaxValue?

我想说:publicvoidProblem(DateTimeoptional=DateTime.MaxValue){}但是编译器提示DateTime.MaxValue不是编译时间常量。DateTime.MinValue很简单,只需使用default(DateTime)另见“HowdoIdefaultaparametertoGuid.EmptyinC#?”我不想使用方法重载,因为我试图驯服的方法有101个参数! 最佳答案 我会用它来代替:publicvoidProblem(DateTime?optional=null){DateTim

c# - 无法从 FILETIME(windows 时间)转换为 dateTime(我得到一个不同的日期)

我阅读的大多数文件在使用以下方法转换时都获得了正确的时间://worksgreatmostofthetimeprivatestaticDateTimeconvertToDateTime(System.Runtime.InteropServices.ComTypes.FILETIMEtime){longhighBits=time.dwHighDateTime;highBits=highBits这里我在visualstudio中有一个例子来展示这种方法有时是如何不起作用的,例如我将展示我电脑中的实际文件和调试。所以恰好在我的调试中的文件是:“A:\Users\Tono\Documents\

C# 字符串到带时区的 DateTime

我想将字符串“2012-04-2010:10:00+0200”格式化为具有这种格式的日期时间。所以我认为它一定是“yyyy-MM-ddhh:mm:sszzz”?当我尝试这个的时候//starttime={20/04/201210:10:00}withoutmy+0200!DateTimestarttime=Convert.ToDateTime("2012-04-2010:10:00+0200",CultureInfo.CurrentCulture);//Andthisgavemeaformatexception:{System.FormatException:Stringwasnotr