Thursday, December 16, 2010

C# DateTime.UtcNow in ISO 8601 date format

Here is the way to get a DateTime.UtcNow string which represents the same value in an ISO 8601 compliant format.

DateTime.UtcNow.ToString("yyyy-MM-ddTHH\:mm\:ss.fffffffzzz");
This gives you a date similar to 2008-09-22T13:57:31.2311892-04:00

Another way is:
============

DateTime.UtcNow.ToString("o"); //my recommendation
which gives you 2008-09-22T14:01:54.9571247Z

♠♪♠♪♠♪♠♪♠♪♠♪♠♪♠♪♠♪

No comments: