[英]How to get browser timezone in javascript then convert into .net timezone id
我只需要知道客户端浏览器的时区,然后我需要将一些事务转换为该客户端浏览器时区。 虽然研发我知道一件事我们无法从 c# 获取浏览器时区,所以是否可以使用 javascript 获取浏览器时区,然后我们可以将其与 .net 时区匹配?
您正在谈论将 IANA 时区转换为 Windows。
IANA 时区: https://www.iana.org/time-zones
您可以在此处找到包含 IANA -> Windows 映射的 XML
https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml
您可以反序列化 XML 并查找 IANA 时区以获取 Windows 之一:
<!-- (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"/>
有一个 NuGet package 在 IANA 和 Windows 时区之间转换
https://www.nuget.org/packages/TimeZoneConverter
您不能在客户端进行此转换,但您可以发送时区名称,然后在服务器上进行转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.