简体   繁体   English

如何从CultureInfo中的属性获取时区

[英]How to get timezone from properties in CultureInfo

I have a string, which contains a timestamp ( yyyy-mm-dd hh:mm:ss ) . 我有一个字符串,其中包含一个时间戳yyyy-mm-dd hh:mm:ss I can create a CultureInfo object based on other information I get. 我可以根据我得到的其他信息创建一个CultureInfo对象。 Therefore I know which country the timestamp is in. The timestamp is not in UTC/GMT. 因此,我知道时间戳所在的国家/地区。时间戳不是UTC / GMT。

Say the timestamp is from Indonesia ( new CultureInfo("id-ID") ) , meaning the string was created by code below or similar. 假设时间戳来自印度尼西亚new CultureInfo("id-ID") ,这意味着该字符串是由下面的代码或类似代码创建的。

DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

That means the string contains the local time in Indonesia. 这意味着该字符串包含印度尼西亚当地时间。 I know my timezone, but I don't know how to convert the Indonesian time to UTC/GMT, so I can use the UTC/GMT object in TimeZoneInfo . 我知道我的时区,但我不知道如何将印度尼西亚时间转换为UTC / GMT,所以我可以在TimeZoneInfo使用UTC / GMT对象。 My own timezone may or may not be in the same timezone. 我自己的时区可能在同一时区,也可能不在同一时区。

Is there anywhere, this information is connected? 有没有,这个信息是连接的?

CultureInfo has a lot of properties, surely some of them can be used to get timezone, somwhere? CultureInfo有很多属性,肯定有些属性可以用来获取时区,somwhere?

I might add that I find the entire system very confusing, so I could be way off in how I think things works. 我可能会补充一点,我发现整个系统非常混乱,所以我觉得我认为事情是如何运作的。

Short answer: No 简答:不

Long Answer: This is a 1 to many relationship between culture and timezone. 长答案:这是文化与时区之间的一对多关系。 For example: en-US - English, American contains 6 timezones... so how would you get from en-US to Eastern Daylight time? 例如:en-US - 英语,美国包含6个时区......那么你如何从美国到东部夏令时? ... and how do you get the daylight savings time offsets? ......你如何获得夏令时补偿?

It's a confusing cultural conundrum (wow, try saying that 5 times fast) that is not easily solvable with the CLR. 这是一个令人困惑的文化难题(哇,试着快5倍),这是CLR难以解决的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM