C# DateTime Millisecond - Java2s.com

文章推薦指數: 80 %
投票人數:10人

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.



請為這篇文章評分?