简体   繁体   中英

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.

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.

I used this :

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

But this is always returning 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)

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