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
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
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(':'));