简体   繁体   中英

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.

What property of the CultureInfo.CurrentCulture is important when I enumerate through all system time zones and want to get the right timezone?

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. 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).

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?

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.

Or you could just... ask them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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