tags:

views:

39

answers:

4

Which format does this stirng 2010-06-19T06:28:01.077148400Z belong to?

It represents 6/19/2010 11:58:01 AM.

I tried parsing the string to DateTime.Parse() and the DateTime object represents the above time. Now I want to convert that DateTime object to the format once again. How can I do that?

+1  A: 

Looks like Universaltime to me.

Grz, Kris.

XIII
What happened with the editing? I don't see a change and why was it needed?
XIII
A: 

This looks like the representation of a DateTime using the Round-trip ("O", "o") Format Specifier:

var s = "2010-06-19T06:28:01.077148400Z";

var dt = DateTime.Parse(s, null, DateTimeStyles.RoundtripKind);

Console.WriteLine(dt.ToString("o"));  //  prints "2010-06-19T06:28:01.0771484Z"
dtb
Did you look at the printed result? "2010-06-19T06:28:01.0771484Z" - note the missing two final 0s.
Jon Skeet
Skeet! You win! But only this time! \*shakes fist\*
dtb
A: 

It looks like UTC formatted in round-trip format.

Stephen Cleary
Not quite: it's got 9 decimal places on the seconds, not 7.
Jon Skeet
I stand corrected. Again. :)
Stephen Cleary
+4  A: 

Given your user information, it looks like you're in an Indian time zone - the New Delhi zone is 5 hours and thirty minutes ahead of UTC. The "Z" at the end of the date/time string indicates UTC, which makes sense: 6:28 UTC is 11:58 in your time zone.

You can take a local DateTime and convert it to UTC using ToUniversalTime - but if you want to get the current time, you can just use DateTime.UtcNow to start with.

Once you've got a DateTime in UTC, this format string would format it in the same way:

yyyy-MM-ddTHH:mm:ss.fffffff00K

This is very similar to the round-trip format, just with the extra two zeroes at the end. Those are hard-coded to 0 as DateTime doesn't have precision beyond a tenth of a microsecond, whereas your sample string has it down to a nanosecond.

For example:

DateTime now = DateTime.UtcNow;
string s = now.ToString("yyyy-MM-ddTHH:mm:ss.fffffff00K",
                        CultureInfo.InvariantCulture);

creates something like this:

2010-06-19T13:57:15.885578200Z
Jon Skeet
Thanks, I figured this out from the answer XIII gave me. But you deserve the credit for giving a detailed answer.
CodingTales