.NET获取时区由区名称偏移 [英] .NET Get timezone offset by timezone name

查看:171
本文介绍了.NET获取时区由区名称偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中,我存储所有日期/时间的UTC。

In database I store all date/times in UTC.

我知道用户的时区名(美国东部标准时间为例)。

I know user's timezone name ("US Eastern Standard Time" for example).

为了显示正确的时间,我在想,我需要添加用户的时区与UTC日期/时间。但如何将我得到时区偏移时区名?

In order to display correct time I was thinking that I need to add user's timezone offset to UTC date/time. But how would I get timezone offset by timezone name?

感谢您!

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx"><$c$c>TimeZoneInfo.FindSystemTimeZoneById使用提供的ID来获得的TimeZoneInfo 对象,然后<一个href="http://msdn.microsoft.com/en-us/library/bb396378.aspx"><$c$c>TimeZoneInfo.GetUtcOffset来自:

You can use TimeZoneInfo.FindSystemTimeZoneById to get the TimeZoneInfo object using the supplied Id, then TimeZoneInfo.GetUtcOffset from that:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time");
TimeSpan offset = tzi.GetUtcOffset( myDateTime);

这篇关于.NET获取时区由区名称偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆