Determine a user’s timezone

Diposting pada

Determine a user’s timezone
Is there a standard way for a web server to be able to determine a user’s timezone within a web page?
Perhaps from an HTTP header or part of the user-agent string?

Answer
-new Date().getTimezoneOffset()/60;

The method getTimezoneOffset() will subtract your time from GMT and return the number of minutes. So if you live in GMT-8, it will return 480.
To put this into hours, divide by 60. Also, notice that the sign is the opposite of what you need – it’s calculating GMT’s offset from your time zone, not your time zone’s offset from GMT. To fix this, simply multiply by -1.

 27 total views,  1 views today

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *