dateTime parser
-
i've converted a dateTime to a string using the following:
[_datetime_].Start.ToString("yyyyMMdd'T'HHmmss");
let's say i've saved this out to a text file and now i'm reading the information back in as a string. how would i then convert this dateTime string back to aSystem.DateTime
object? thanks, Rob Tomson -- There are 10 kinds of people. Those who understand binary and those who don't. -
i've converted a dateTime to a string using the following:
[_datetime_].Start.ToString("yyyyMMdd'T'HHmmss");
let's say i've saved this out to a text file and now i'm reading the information back in as a string. how would i then convert this dateTime string back to aSystem.DateTime
object? thanks, Rob Tomson -- There are 10 kinds of people. Those who understand binary and those who don't.If you use the built-in format provider with the switch 's' you get aery similar format to yours above and you can use the parse static method on a DateTime...eg:
string s = DateTime.Now.ToString("s"); Console.WriteLine(s); DateTime parsedDateTime = DateTime.Parse(s); Console.WriteLine(parsedDateTime);
the "S" switch is defined as this format in the Docs: 2002-01-03T00:00:00 yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern) If you really want your own format then you can write your own class which implements IFormatProvider, or inherits from DateTimeFormatInfo. DateTimeFormatInfo[^]