如何在另一个时区获得当地时间

时间:2015-11-09 11:12:57

标签: javascript timezone

使用纯javascript(没有jquery或插件),如何将一个本地时间转换为另一个时区?

对于情况:

我正在做一个倒数计时器,我已将结束日期设为javascript变量。我想将该变量转换为本地时间,具体取决于客户端位置/时区。

var maintenanceEndDate = new Date("11/10/2015 00:00"); //This is the initial time,  based on the administrator's location
var maintenanceEndDateOffset = ????  //The above time converted to local time

然后我想将两者都转换为UTC。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

您可以用UTC指定维护结束时间,让本地浏览器为您处理时间转换:



>> A=1:(3*4*5*6);
>> A=reshape(A,3,4,5,6);




答案 1 :(得分:0)

var now = new Date();

这将为您提供客户日期和时间。

now.getTimezoneOffset()

将为您提供该时区与UTC之间的偏差。

答案 2 :(得分:0)

我建议您深入了解您所需要的momentjs库:http://momentjs.com/http://momentjs.com/timezone/

相关问题