/    Sign up×
Community /Pin to ProfileBookmark

Detect Local Time Zone

How to write detect local time zone from client ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@cyberowlDec 13.2006 — From http://www.w3schools.com

<script type="text/javascript">

var d = new Date()

var gmtHours = d.getTimezoneOffset()/60

document.write("The local time zone is: GMT " + gmtHours)

</script>[/QUOTE]
Copy linkTweet thisAlerts:
@mrhooDec 13.2006 — If you want to return the actual name of the time zone it's

a little hit or miss- different browsers return different strings.

Microsoft IE returns values like 'EST', while the mozillas return

'Eastern Standard Time'; and I can't find it at all in Opera.

(I hope somebody using Safari can confirm it returns a timeString

like Mozilla)

You can cover the bases with this:
[CODE]var tz= function(){
var D=new Date()
var str=D.toTimeString();
M=str.match(/(GMT[^(]+()?([a-z ]+))?$/i);
return (M && M[2])? M[2]:
'GMT plus '+(D.getTimezoneOffset()/60).toFixed(1)+' hours';
}[/CODE]
×

Success!

Help @saturngod spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...