Skip to content Skip to sidebar Skip to footer

Get Current Time In A Specific Country Via Jquery

I want to show the current time in New Zealand using JQuery. My client has customers calling from outside New Zealand. However, he gets annoyed that customers call at 3 am because

Solution 1:

The JavaScript Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

functionDisplayCityTime(city, offset) {
    // Date object for current locationvar aDate = newDate();

    // UTC time in msecvar utc = adate.getTime() + (adate.getTimezoneOffset() * 60000);

    // Date object for the requested cityvar newdate = newDate(utc + (3600000*offset));

    // return time as a stringreturn"The local time for city : "+ city +" is "+ newdate.toLocaleString();
}

alert(DisplayCityTime('Montreal', '-5'));

Solution 2:

When daylight saving is not being observed in New Zealand, NZST is GMT+12:00.

Daylight saving in NZ commences on the last Sunday in September, when 0200 becomes 0300, and ends on the first Sunday in April, when 0300 becomes 0200. NZDT is GMT+1300

There are a number of time services that you can query to get the current time in any time zone, try answers to this question: Web service - current time zone for a city?.

So the server, wherever it is in the world, no matter how it's configured, simply gets the current time in NZ as required and sends it to the client. You can probably do it from the client too, but the server will be more reliable.

It's trivial to do a time conversion in javascript, however adjustments for daylight saving and reliance on local client settings mean it's not particularly robust or reliable.

Post a Comment for "Get Current Time In A Specific Country Via Jquery"