For a little more color
2011-11-28T07:21:41.000Z
This is a ISO8601 Timestamp, the Z at the end means UTC time. This represents a specific instant in time.
DateTime.Parse
will return to you a local date time structure, there are three types of datetime kinds, UTC, Local, and Unspecified.
If you try displaying this, it will show you this instant in your computers current timezone (I'm eastern time so when I print it I get 11/28/2011 2:21:41 AM
).
If I want to switch this DateTime Kind
to UTC, I could do something like
DateTime.Parse("2011-11-28T07:21:41.000Z").ToUniversalTime()
Printing this now (since it's kind is now UTC) I get 11/28/2011 7:21:41 AM
.
Note that although the time is printed differently both these date times are referring to the same instant in time.
To display this instant in a different timezone, the easiest way imo is the TimeZoneInfo class (though I'm not sure it's 100% accurate).
TimeZoneInfo.ConverTimeBySystemTimeZoneId(dateTime, "Pacific Standard Time").
Printing it now will yield your desired result 11/27/2011 11:21:41 PM
Note that this return DateTime's Kind
property is now Unspecified
, meaning you won't be able to transfer it back to UTC without more information. You no longer have a specific instant in time, rather you have a unspecified time..we know it's the same instant as the ones previously just in pacific time, but the computer no longer knows that. Keep that in mind if you want to store this time.