ConvertTimeFromUtc in WP7?
Someone knows why ConvertTimeFromUtc don't work in wp7?
DateTime convDateTime = TimeZoneInfo.ConvertTimeFr开发者_运维问答omUtc(date, zone);
Thank!
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.
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)
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;
}
精彩评论