DateTime.ToString pattern to preserve even the smallest part
I need to store exact DateTime
as a filename, and restore it when needed.
Pattern dd_MM_yyyy hh_mm_ss_ff tt
doesn't seem to match the original date (after using DateTime.ParseExact
, so I believe part of the date is lost upon conversion. Is ticks the smallest pa开发者_开发百科rt of DateTime? How to save it to string as well?
I believe you want to reliably time-stamp your log file. Well, the format you provide will not be reliable, i.e. it will look different depending on Thread's CurrentCulture value.
I would recommend using something like "yyyy-MM-dd_HH:mm:ss.FFFFFFF" if you want to have precise and reliable time stamp.
Yes, ticks represent the smallest measurement on a DateTime.
String filename = DateTime.Now.Ticks + ".txt";
精彩评论