草庐IT

sonata_type_datetime_picker

全部标签

c# - 在 C# 中从 SQL 数据库读取 DateTime 值时没有毫秒值

我将高精度日期存储在SQL服务器中,例如2009-09-1519:43:43.910但是,当我将该值转换为DateTime时,生成的DateTime值的毫秒值为0:reader["Timestamp"]=15/09/200919:43:43.000将这些DateTime值精确到毫秒对我来说非常重要-最好的方法是什么?更新:这是执行转换的代码:DateTimemyDate=(DateTime)reader[Timestamp"];SELECT语句没有什么特别的,实际上它是一个SELECT*-没有花哨的转换或任何东西SqlDataReader返回的DateTime对象似乎没有填充毫秒值

c# - 为什么 DateTime.Parse 这么慢?

我对DateTime.Parse的速度之慢感到震惊。此代码运行大约需要100秒;如果我使用正则表达式版本,则需要100毫秒。这是怎么回事?Stopwatchsw=newStopwatch();sw.Start();varre=newRegex(@"(\d\d)/(\d\d)/(\d\d\d\d)(\d\d):(\d\d):(\d\d)",RegexOptions.Compiled);for(inti=0;i编辑:Mark是对的,将CultureInfo.CreateSpecificCulture("en-US")移到循环外很有帮助。我之前没有这样做的原因是我使用VSProfiler分析

c# - "The type or namespace name ' 引用System.Xml.dll时XmlSerializer ' could not be found"错误

我已经在这上面浪费了几个小时:XmlSerializerserializer;是的,using在那里,引用在那里,我在VS2010中使用.NET4.0制作了整个解决方案,所以它不是那些东西。如果我进入对象资源管理器,我可以在正确的命名空间中找到我想要的XmlSerializer类,但是如果我尝试在我的代码文件中键入上面的行并进行编译,我会得到可怕的Thetypeornamespacename'XmlSerializer'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)死亡警告。我也没有在Intelli

c# - .NET DateTime 线程安全吗

.NETDateTime线程安全吗?如果read操作返回不正确的值,我并不担心,我唯一担心的是:如果不同步,DateTime对象是否会损坏。 最佳答案 读取和写入DateTime字段不是原子的(至少在32位系统上)。如果您同时从多个线程分配同一个属性,您可能会破坏它。如果您从一个线程读取并从另一个线程写入,读取线程可能会获得损坏的值。从多个线程读取而同时没有写入线程是安全的。本质上,当同时从多个线程使用时,DateTime的两个32位半部分可能包含不同年龄的值。您可以混合使用两种写入方式。一个写的高32位部分,另一个写的低32位部分

c# - 如何创建可选的 DateTime 参数?

我有一个返回引用类型的函数。现在,这个函数有两个可选参数,它们都是DateTime类的实例。函数是这样的:publicDateTimeGetDate(DateTimestart=DateTime.MinValue,DateTimeend=DateTime.MinValue){//Methodbody...}VS的错误是:Defaultparametervaluefor'start'mustbeacompile-timeconstant当然,错误适用于第二个参数,我完全理解发生了什么。我真正想要的是知道是否有办法解决这个问题,即在方法中包含可选参数。现在,我所做的是创建一个过载;我的意思

c# - DateTime.Now 检索速度

这个语句是否有可能返回trueDateTime.Now==DateTime.Now一个非常快的机器可以为这条语句返回true吗,我在几台机器上试过,它总是false? 最佳答案 是的。Theresolutionofthispropertydependsonthesystemtimer,whichisapproximately15millisecondsonWindowssystems.Asaresult,repeatedcallstotheNowpropertyinashorttimeinterval,suchasinaloop,m

c# - Linq to Entity 从 DateTime 获取日期

varislemList=(fromislinentities.Islemlerwhere(isl.KayitTarihi.Date>=dbas&&isl.KayitTarihi.Value.Date它给出错误:LINQtoEntities不支持日期...我如何在linq中获取日期。 最佳答案 使用EntityFunctions.TruncateTime. 关于c#-LinqtoEntity从DateTime获取日期,我们在StackOverflow上找到一个类似的问题:

c# - 为什么 C# 中没有 System.DateTime 的 "date"简写?

如int,long,ushort,uint,short,等等。为什么没有System.DateTime的简写? 最佳答案 Manytypesareassociatedwith"shorthand"keywordsinC#;forexample,System.Int32canalsobewrittenintandSystem.Stringcanbewrittenstring.Whyisn'tthereashorthandforSystem.DateTime?在我回答这个问题之前——或者更确切地说,没有回答它——让我们首先注意在C#中有

c# - 通缉 : DateTime. TryNew(year, month, day) or DateTime.IsValidDate(year, month, day)

标题基本上说明了一切。我从旧数据库(我无法更改)。目前,我使用以下代码将这些整数解析为DateTime结构:try{returnnewDateTime(year,month,day);}catch(ArgumentExceptionex){returnDateTime.MinValue;}有时,这些值并不代表有效日期(是的,用户输入了诸如1999-06-31之类的内容,但不,旧版应用程序并未对此进行验证)。自throwinganexceptionwhendatavalidationfailsisconsideredbadpractice,我更愿意用无异常代码替换它。然而,我能找到的唯一

c# - "Compile with/main to specify the type that contains the entry point."

根据下面的代码,我收到以下消息。我相当确定我得到它的“原因”,我只是不知道如何重新排列代码以移动/删除/替换导致错误的语句之一。“使用/main编译以指定包含入口点的类型。”"staticvoidMain(string[]args)"下有一堆代码,我从http://support.microsoft.com/kb/816112为了从自动递增中获取ID,所以当其余代码填充Access数据库时,我可以让它自动递增。任何帮助表示赞赏。也欢迎使用更简单的代码获得结果的建议!namespaceWindowsFormsApplication1{publicpartialclassForm1:For