通过jquery获取特定国家/地区的当前时间 [英] get current time in a specific country via jquery
问题描述
我想用JQuery显示新西兰的当前时间。我的客户有来自新西兰境外的客户。然而,他很恼火,客户在凌晨3点打电话,因为他们没有想到时差。他想添加一个标签,上面写着新西兰当前时间是:早上3点。它可以通过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 they did not think of the time difference. He wants to add a label saying "Current time in New Zealand is: 3.00 am". Can it be achieved via JQuery? Cheers.
推荐答案
JavaScript Date对象支持许多UTC(通用)方法以及本地时间方法。 UTC,也称为格林威治标准时间(GMT),是指世界时间标准设定的时间。本地时间是执行JavaScript的计算机已知的时间。
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.
function DisplayCityTime(city, offset) {
// Date object for current location
var aDate = new Date();
// UTC time in msec
var utc = adate.getTime() + (adate.getTimezoneOffset() * 60000);
// Date object for the requested city
var newdate = new Date(utc + (3600000*offset));
// return time as a string
return "The local time for city : "+ city +" is "+ newdate.toLocaleString();
}
alert(DisplayCityTime('Montreal', '-5'));
这篇关于通过jquery获取特定国家/地区的当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!