Which format does this stirng 2010-06-19T06:28:01.077148开发者_如何学JAVA400Z
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?
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
Looks like Universaltime to me.
Grz, Kris.
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"
It looks like UTC formatted in round-trip format.
精彩评论