Microsoft

C# Full Timestamp

Because I’m always having to look this up… a full (useful) timestamp should always look like this…

YYYYMMDD HH:MM:SS.fff   => 20200730 14:58:00.000   

string timeStamp = DateTime.Now.ToString("yyyyMMdd hh:mm:ss.fff tt");  //Example 20200730 03:02:39.591 PM
string fileTimeStamp = DateTime.Now.ToString("yyyyMMdd_HHmmssfff");    //20200730_150535040
string fileTimeStamp2 = DateTime.Now.ToString("yyyyMMdd_hhmmssffftt");// 20200730_030707929PM

 

~SG

 

Leave a Reply