简体   繁体   中英

How to get browser timezone in javascript then convert into .net timezone id

I Just need to know the timezone from client browser then i need to convert some transactions into that client browser timezone. while R&D i understood one thing we cannot get browser timezone from c# so is it possible to get browser timezone using javascript then we can match that with .net timezone?

You are talking about converting IANA timezone to Windows.

IANA timezone: https://www.iana.org/time-zones

You can find an XML containing the IANA -> Windows mapping here

https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml

You can deserialize that XML and look for the IANA timezone to get the Windows one:

<!-- (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi -->
<mapZone other="India Standard Time" territory="001" type="Asia/Calcutta"/>
<mapZone other="India Standard Time" territory="IN" type="Asia/Calcutta"/>

There's a NuGet package to convert between IANA and Windows timezone

https://www.nuget.org/packages/TimeZoneConverter

You cannot do this conversion on the client side but you can send the timezone name and then convert it on the server.

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