C# DateTime Millisecond - Java2s.com
文章推薦指數: 80 %
C# Tutorial - C# DateTime Millisecond. ... Description. DateTime Millisecond gets the milliseconds component of the date represented by this instance. Next »DateTime (2917/5847)« PreviousC#DateTimeMillisecondDescriptionDateTimeMillisecondgetsthemillisecondscomponent ofthedaterepresentedbythisinstance.SyntaxDateTime.Millisecondhasthefollowingsyntax. publicintMillisecond{get;} Example DisplaythestringrepresentationoftheMillisecondpropertybyusingthe"fff"formatspecifier. Forexample,thefollowingcodedisplaysastringthatcontainsthenumberofmillisecondsina dateandtimetotheconsole. usingSystem;/*fromwww.java2s.com*/ publicclassMainClass{ publicstaticvoidMain(String[]argv){ DateTimedate1=newDateTime(2008,1,1,0,30,45,125); System.Console.WriteLine("Milliseconds:{0:fff}", date1);//displaysMilliseconds:125 } } Thecodeabovegeneratesthefollowingresult. Example2 Youcanalsodisplaythemillisecondcomponenttogetherwiththeothercomponents ofadateandtimevaluebyusingthe"o"standardformatspecifier.Forexample: usingSystem;//www.java2s.com publicclassMainClass{ publicstaticvoidMain(String[]argv){ DateTimedate2=newDateTime(2008,1,1,0,30,45,125); System.Console.WriteLine("Date:{0:o}", date2); } } Thecodeabovegeneratesthefollowingresult. Example3 Youcanalsodisplaymillisecondstogetherwithotherdateandtime componentsbyusingacustomformatstring,asthefollowingexampleshows. usingSystem;/*fromwww.java2s.com*/ publicclassMainClass{ publicstaticvoidMain(String[]argv){ DateTimedate3=newDateTime(2008,1,1,0,30,45,125); Console.WriteLine("Datewithmilliseconds:{0:MM/dd/yyyhh:mm:ss.fff}", date3); } } Thecodeabovegeneratesthefollowingresult. Example4 ThefollowingexampledemonstratestheMillisecondproperty. usingSystem;/*fromwww.java2s.com*/ publicclassMainClass{ publicstaticvoidMain(String[]argv){ System.DateTimemoment=newSystem.DateTime(1999,1,13,3,57,32,11); intmillisecond=moment.Millisecond; System.Console.WriteLine(); } } Next »« PreviousHome » C#Tutorial » System »ArrayBitConverterBooleanByteCharConsoleConsoleKeyInfoConvertDateTimeDateTimeOffsetDecimalDoubleEnumEnvironmentExceptionGuidInt16Int32Int64MathOperatingSystemRandomSByteSingleStringStringComparerTimeSpanTimeZoneTimeZoneInfoTupleTupleTupleTypeUInt16UInt32UInt64UriVersionjava2s.com | ©DemoSourceandSupport.Allrightsreserved.
延伸文章資訊
- 1作法:在日期與時間值中顯示毫秒 - Microsoft Docs
若要擷取時間毫秒元件的字串表示,請呼叫日期和時間值的DateTime. ... ToString("fff")); // Display Millisecond component with f...
- 2c# - How to format a string as a date with milliseconds - 1400+ ...
DateTime now = DateTime.Now; Label1.Text = "now: " + now.ToString(); //format date time with mill...
- 3Get DateTime.Now with milliseconds precision - Stack Overflow
I have an application, where I sample values 10 times per second, and I need to show them in a gr...
- 4How to show time with milliseconds in Excel? - ExtendOffice
- 5C#的Datetime進DB少一毫秒之問題解決方式 ... - Coding Girl - Mia
C#的Datetime進DB少一毫秒之問題解決方式(C# Datetime into MSSQL DB lose one millisecond). 前言&解決方法: 將資料存進DB時發現毫秒數...