Create a new .NET Core console project, type the following code:
the using the System; namespace NetCoreDatetime { class Program { static void the Main ( String [] args) { the DateTime now = the DateTime.Now; // Current Time: 2019-09-25 15: 56 is: 56.673 // YYYY year, MM month, dd day, HH (24 hour), mm minutes, ss seconds, fff milliseconds String txtDate = now.ToString ( " YYYY the mM-dd-HH: mm: ss.fff " ); // show: 2019-09-25 15: 56 is: 56.673 Console.WriteLine (txtDate); // YYYY year, mM month, dd day, hh (12 hour clock), mm minutes, ss seconds, milliseconds FFF txtDate = now.ToString ( "yyyy-MM-dd hh:mm:ss.fff");//显示:2019-09-25 03:56:56.673 Console.WriteLine(txtDate); Console.WriteLine("Press any key to end..."); Console.ReadKey(); } } }
Note formats, differences in uppercase and lowercase hh HH difference between uppercase and lowercase mm MM, do not be confused.
references:
Get DateTime.Now with milliseconds precision