dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Friday May 18th 2018 by Srinath M S

Language: .NET, Expertise: Intermediate - DateTimeOffSet values are often converted to strings for display but they often fail when they are converted back.

DateTimeOffSet values are often converted to strings for display or some other purpose. But these representations often fail when they are used to convert them back to valid date/time values.

We need to use the ToString method's overload and pass the "u" or "s" formats as they are culture-invariant.

For example:

DateTimeOffSet d = DateTimeOffSet.Now;
Console.WriteLine(d.ToString("u"));
Home
Mobile Site | Full Site