简体   繁体   English

在javascript中获取客户端的确切时区

[英]Get exact timezone of client in javascript

I need to know exact timezone of the client regardless if it is falling under list of timezones having same GMT.我需要知道客户端的确切时区,无论它是否属于具有相同 GMT 的时区列表。

EX:前任: 在此处输入图片说明

Here if a user is from Cairo, how can I identify from javascript if he is from Cairo.There are too many countries which fall under same GMT.在这里,如果用户来自开罗,我如何从 javascript 中识别他是否来自开罗。有太多国家属于同一 GMT。

I used this :我用过这个:

var timezone = new Date().toTimeString().split("(");
console.log( timezone[1].toString().replace(")", ""));

But this is always returning Eastern Europe Standard Time .但这总是返回Eastern Europe Standard Time

I am stuck, and I dont know how to achieve this.我被卡住了,我不知道如何实现这一目标。

Basically I have populated a dropdown with all Timezones from Server side, and I need to how can i select the timezone depending upon the users current timezone.基本上我已经从服务器端填充了所有时区的下拉列表,我需要如何根据用户当前时区选择时区。

在此处输入图片说明

不要使用 Date 对象,而是尝试使用像这样的Internationalization API兼容性):

 console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

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

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