.NET获取时区由区名称偏移时区、由区、名称、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 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?

感谢您!

推荐答案

您可以使用TimeZoneInfo.FindSystemTimeZoneById使用提供的ID来获得的TimeZoneInfo 对象,然后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);
阅读全文

相关推荐

最新文章