3

Possible Duplicate:
Getting the client’s timezone in JavaScript

Is there anyway to get current timezone in javascript. All i see is

Date.getTimeZoneOffset()

The problem I am facing is, I have a piece of functionality which allows the users to download pdf, now the pdf has to include a 'download date' in it which should be users local date, have to do this in java. But its all confusing, I dont know if i should locale or not or just the timezone will work, each time when i try something the results are different!!!!

Community
  • 1
  • 1
Toseef Zafar
  • 1,601
  • 4
  • 28
  • 46
  • 2
    That would be the current timezone... – Shmiddty Nov 13 '12 at 17:15
  • 1
    Do you mean the time zone name, such as "CET" or "Europe/Madrid"? – Álvaro González Nov 13 '12 at 17:15
  • https://bitbucket.org/pellepim/jstimezonedetect – Esailija Nov 13 '12 at 17:15
  • similar to: http://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript – Chase Nov 13 '12 at 17:15
  • 2
    @Shmiddty UTC offset is not a timezone, the offset changes depending on the computer's real timezone and the date object's value whereas a timezone like 'Europe/London' encapsulates the DST changes and offsets depending on time. – Esailija Nov 13 '12 at 17:16
  • 3
    Please *don't close* this as a duplicate for that question without reading it through first; as the other question (and accepted answer) focus on the *offset* via `getTimeZoneOffset` which was mentioned in the question here .. –  Nov 13 '12 at 17:27
  • Seconded. The supplied duplicate's topic is offset. This question is about timezones (presumably Olson timezones e.g. "Europe/London"). – Stephen Kennedy Oct 28 '14 at 09:34

1 Answers1

7

Use Date.toTimeString()

Code:

var date = new Date();
document.write(date.toTimeString());

Output:

22:53:21 GMT+0530 (India Standard Time)
              ^offset     ^timezone
Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
  • 2
    I get `new Date( 2012, 0 ).toTimeString(); //"00:00:00 GMT+0200 (FLE Standard Time)"` and `new Date( 2012, 6 ).toTimeString(); //00:00:00 GMT+0300 (FLE Daylight Time)` which are not that useful, when a simple `Europe/Helsinki` would have encapsulated all of this in a single timezone. – Esailija Nov 13 '12 at 17:52
  • 1
    @Esailija In any case, that library you mentioned will serve better. I was just trying to find that piece of information using built-in functions. – Anirudh Ramanathan Nov 13 '12 at 17:57
  • 1
    The problem I am facing is, I have a piece of functionality which allows the users to download pdf, now the pdf has to include a 'download date' in it which should be users local date, have to do this in java. But its all confusing, I dont know if i should locale or not or just the timezone will work, each time when i try something the results are different!!!! – Toseef Zafar Nov 14 '12 at 10:39
  • 1
    If you are looking for the date, JS won't really be reliable. Can't use the server-side date? – Anirudh Ramanathan Nov 14 '12 at 11:23