Reputation: 297
Someone knows why ConvertTimeFromUtc don't work in wp7?
DateTime convDateTime = TimeZoneInfo.ConvertTimeFromUtc(date, zone);
Thank!
Upvotes: 1
Views: 560
Reputation: 13537
Try something like the following to convert from a DateTime known to be in UTC to the local timezone.
public static DateTime LocalDateTimeFromUtc(DateTime utcDateTime)
{
DateTimeOffset dateTimeOffset = new DateTimeOffset(utcDateTime, new TimeSpan(0, 0, 0));
DateTimeOffset dateTimeOffsetConvertedToLocal = TimeZoneInfo.ConvertTime(dateTimeOffset, TimeZoneInfo.Local);
return dateTimeOffsetConvertedToLocal.DateTime;
}
Upvotes: 0
Reputation: 856
you can use addhours method to solve this promble. for example: utc time :2011-08-24 06:25:37 in china +8 hours so in china, the time is :2011-08-24 15:25:37 = 2011-08-24 06:25:37(date)+8(zone)
Upvotes: 0
Reputation: 1340
The Windows Phone 7 .Net framework does not support the ConvertTimeFromUtc function at this time.
For my application I used the ZoneInfo .Net API classes. These use the publicly available timezone database (tz Database / Olson Database). I needed to adapt the classes to read the timezone DB files from Resource streams since Disk IO isnt available on WP7, but other than that the classes all worked well.
Upvotes: 2