简体   繁体   English

使用c#获取当前文化信息的时区

[英]Get timezone by current culture info with c#

I need to know the timezone for a certain language which I get from the current culture info object. 我需要知道从当前文化信息对象获得的某种语言的时区。

I can not use 3rd party libs like nodatime. 我不能使用像nodatime这样的第三方库。

What property of the CultureInfo.CurrentCulture is important when I enumerate through all system time zones and want to get the right timezone? 当我枚举所有系统时区并希望获得正确的时区时,CultureInfo.CurrentCulture的哪些属性很重要?

If all you've got is culture, that's basically some string like: MX (Spanish Mexico), es-CO (Spanish Columbia), and fr-CA (French Canada) then you just have to correspond each on of these to a timezone, except no such one to one relationship exists. 如果你所拥有的只是文化,那基本上就是一些字符串: MX (Spanish Mexico), es-CO (Spanish Columbia), and fr-CA (French Canada)那么你只需将这些字符串对应一个时区,除了不存在这样的一对一关系。 So no. 所以不行。 You can roughly know the timezone (as pointed out in comments), fr-CA is all in the same timezone, but MX is in four (MX isn't enough information to gauge timezone). 你可以粗略地知道时区(正如评论中所指出的),fr-CA都在同一时区,但MX是四(MX不足以测量时区信息)。

So you don't have enough data to know, what can you do. 所以你没有足够的数据知道,你能做些什么。 If you need to know their timezone on the server side try geo-location: How can I find a user's GEO Location using ASP.NET? 如果您需要在服务器端知道他们的时区,请尝试地理位置: 如何使用ASP.NET查找用户的GEO位置?

However, if it's just the web page that needs to know, try putting that logic in the JavaScript which is executing on their machine. 但是,如果它只是需要知道的网页,请尝试将该逻辑放在其计算机上执行的JavaScript中。

Or you could just... ask them. 或者你可以......问问他们。

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

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