获取 WP7 中的 UTC 偏移量
有谁知道在 WP7 中获取 UTC 偏移量的最佳方法?显然 TimeZone api 尚未在那里实现。
谢谢
Does anyone know the best way to get the UTC offset in WP7? Apparently the TimeZone api hasn't been implemented there.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用
DateTimeOffset.Now.Offset
...这就是为什么 DateTimeOffset 已创建!Just use
DateTimeOffset.Now.Offset
... that is why DateTimeOffset was created!如果您只想转换为本地时间,请使用
DateTime.ToLocalTime()
。如果你想要偏移量,我想你可以减去原始值。 文档。If you just want to convert to local time, use
DateTime.ToLocalTime()
. If you want the offset, I think you can subtract the original value. Documentation.我最近做了类似下面的事情;这很快就完成了,但很有效。就我而言,我总是想要东部时区的时间,因为那是我的应用程序的活动地点。存储为 UTC 和计算的偏移量。
I recently did something like the below; this was done quickly but it works. In my case I always wanted time as of eastern time zone since that is where the event my app was for. Stored as UTC and calculated offset.