获取具有当前本地日期时间和GMT日期时间的TimeZone Id [英] Get TimeZone Id with Current Local dateTime annd GMT datetime

查看:903
本文介绍了获取具有当前本地日期时间和GMT日期时间的TimeZone Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如何在c#中获取TimeZone ID。我有GMT中的DateTime和本地DateTime或以分钟为单位的偏移值。




Jameson M Tinoy

解决方案

有多个时区具有相同的偏移量,因此给定一个偏移量,你无法到达它的时区(因为可能有倍数)。有关更多信息,请参阅

MSDN


您可以使用 $获取当地时区b $ b TimeZonInfo.Local 。您可以使用
GetSystemTimeZones
在计算机上获取可用时区。您可以使用
CreateCustomTimeZone
创建自定义时区。给定偏移量,您可以获得匹配时区列表,忽略夏令时问题。


我不清楚您尝试使用UTC和当地时间做什么。您可以使用标准DateTime方法将一个转换为另一个。例如,如果您想知道2次之间的差异,那么将它们转换为UTC然后进行比较。


如果您的DateTime没有时区信息(典型值),但您知道它所在的时区,那么您可以使用

ConvertTime
方法。


Hello,

How can i get the TimeZone Id in c#. I have the DateTime in GMT and local DateTime or the offset value in minutes.


Jameson M Tinoy

解决方案

There are multiple timezones with the same offsets so given an offset you cannot get to the timezone for it (as there may be multiples). Refer to MSDN for more information.

You can get the local timezone using TimeZonInfo.Local. You can get the available time zones on a machine using GetSystemTimeZones. You can create custom time zones using CreateCustomTimeZone. Given an offset you could get the list of matching time zones, ignoring daylight savings time issues.

It is unclear to me what you're trying to do with the UTC and local times. You can convert one to the other using the standard DateTime methods. For example if you wanted to know the difference between 2 times then convert them to UTC and then compare them.

If you have a DateTime with no time zone information (typical) but you know what timezone it is in then you can use the ConvertTime method.


这篇关于获取具有当前本地日期时间和GMT日期时间的TimeZone Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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