Automatically detect user’s current local time with JavaScript or PHP

With JavaScript, there is a way to get the users current timezone offset.

new Date().getTimezoneOffset() * -1

returns the offset in minutes from GMT. Do not store this value as it can change depending on Daylight Saving Time. If you need it on the server (php) then you’ll need to capture it in send it.

Unfortunately, the HTTP spec doesn’t send the users timezone as a header, which is what php would need.

Leave a Comment