【发布时间】:2011-07-17 03:26:01
【问题描述】:
我需要能够在几分钟内知道运行我的应用程序的设备的时区偏移量。例如,对于太平洋标准时间(我正在测试),我需要获取 int -480。示例(我应该无法从我当前的位置获得 - 但让您了解我需要什么)在阿富汗,我会得到 270,而英国是我会得到 0 的地方。
到目前为止,我的最佳尝试都返回了 0,这是错误的值:
int timezoneOffsetInMinutes = (DateTime.Now.ToLocalTime() - DateTime.Now).Minutes// returns 0 instead of the expected -480
和
int timezoneOffsetInMinutes = TimeZoneInfo.Utc.BaseUtcOffset.Minutes - TimeZoneInfo.Local.BaseUtcOffset.Minutes;// also returns 0, not -480
我不确定this post 是否在问同样的问题(因为没有给出示例偏移量或示例代码),但那里给出的一个答案肯定与我正在寻找的内容无关。
【问题讨论】:
标签: c# .net datetime windows-phone-7 timezone