我正在使用TimeZone.CurrentTimeZone来获取用户与UTC的时间偏移,如下所示:
TimeZone zone = TimeZone.CurrentTimeZone;
TimeSpan offset = zone.GetUtcOffset(DateTime.Now);
return offset.Hours*60+offset.Minutes;
当我为Android,iOS,Blackberry构建时,这是有效的,但在WM8上,我收到以下构建错误:
错误:'System.TimeZone'不存在于目标框架中。我知道目标框架是ASP.NET 2.0的一个子集
有人可以提出另一种获得UTC偏移的方法吗?
答案 0 :(得分:3)
TimeZoneInfo
and its GetUtcOffset(DateTime)
。
所以你可以这么做:
TimeSpan delta = TimeZoneInfo.Local.GetUtcOffset();
double offset = delta.TotalMinutes;
答案 1 :(得分:0)