I have this UTC+0 Date :
2011-11-28T07:21:41.000Z
and I'd like, on C#, convert it to a PST Date. How can I do it? Tried with :
object.Data.ToLocalTime()
but I can't get the correct value (which should be 2011-11-27)
Also tried (after suggesion on another topic) this :
DateTime convertedDate = DateTime.SpecifyKind(
DateTime.Parse(object.Data.ToShortDateString()),
DateTimeKind.Utc);
DateTime dt = convertedDate.ToLocalTime();
string dataVideo = dt.ToShortDateString();
but the date still 28/11/2011, not 27/11/2011
I've changed my clock to use UTC-08:00 Pacific Time
.
DateTime timestamp = DateTime.Parse("2011-11-28T07:21:41.000Z");
Console.WriteLine("UTC: " + timestamp.ToUniversalTime());
Console.WriteLine("PST: " + timestamp.ToLocalTime());
Output:
UTC: 28/11/2011 7:21:41
PST: 27/11/2011 23:21:41
Example with TimeZoneInfo
DateTime timestamp = DateTime.Parse("2011-11-28T07:21:41.000Z");
Console.WriteLine("UTC: " + timestamp.ToUniversalTime());
Console.WriteLine("GMT+1: " + timestamp.ToLocalTime());
Console.WriteLine("PST: " + TimeZoneInfo.ConvertTimeBySystemTimeZoneId(timestamp, "Pacific Standard Time"));
Output:
UTC: 28/11/2011 7:21:41
GMT+1: 28/11/2011 8:21:41
PST: 27/11/2011 23:21:41
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With