I have the following issue with handling datetime formats for a component I am developing.
string value = DateTime.Now.ToString( ); // value = "8/3/2010 2:20:49 PM"
How do I find out which date format value refers to –> "M/d/yyyy h:mm:ss tt"
I wish to store this current datetime format during export and use the same during import. Various apis available in DateTimeFormatInfo.CurrentInfo and CultureInfo.CurrentCulture.DateTimeFormat do not provide this info.
One solution I know of is to use dt.ToString( “u” ) to store and parse datetime in universal format, but I am curious how I could get the above format.
Per the documentation:
Following the doc links Formatting Overview -> Date And Time Format Strings -> Standard DateTime Format Strings gets us to
So the format you want should be obtainable by combining the
ShortDatePatternandLongTimePatternmembers ofThread.CurrentThread.CurrentCulture.DateTimeFormat.