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