-1

How can I get current time of a given timezone using jQuery ?

I have a dropdown where user select the timezone (i.e. PST or EST etc.) and I need to display current time based on the selected timezone

Pinal Dave
  • 533
  • 4
  • 14
  • 27
  • Do you have the UTC Offset of each timezeone? http://en.wikipedia.org/wiki/UTC_offset – Greg Jan 26 '14 at 00:40
  • Googling `how to get current time of a given timezone using jQuery` brings up plenty of options, for example [get current time in a specific country via jquery](http://stackoverflow.com/q/18392482) – Pekka Jan 26 '14 at 00:42
  • Try this plugin: http://momentjs.com/timezone/ check this: http://stackoverflow.com/a/18648135/2611927 – Hardy Jan 26 '14 at 00:42
  • possible duplicate of [get current time in a specific country via jquery](http://stackoverflow.com/questions/18392482/get-current-time-in-a-specific-country-via-jquery) – Pekka Jan 26 '14 at 00:42

1 Answers1

0

You can use the Date object for that. To get a local timestamp, just use the getter methods that don't have getUTC at the start of their name.

For example, to get a timestamp in the form of YYYY-MM-DD hh:mm:ss, you'd do this:

var d = new Date();
var date = [d.getFullYear(), d.getMonth(), d.getDate()],
    time = [d.getHours(), d.getMinutes(), d.getSeconds()];
alert("It's now: "+date.join('-')+' '+time.join(':'));
Joeytje50
  • 18,636
  • 15
  • 63
  • 95