在JavaScript中将日期转换为另一个时区 [英] Convert date to another timezone in JavaScript

查看:142
本文介绍了在JavaScript中将日期转换为另一个时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个将一个时区的日期转换为另一个时区的功能。

I am looking for a function to convert date in one timezone to another.

需要两个参数,


  • 日期(格式为2012/04 / 10 10:10:30 +0000)

  • 时区字符串(亚洲/雅加达)

时区字符串在 http://en.wikipedia.org/wiki/Zone中有所描述.tab

有一种简单的方法吗?

推荐答案

var aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"});
aestTime = new Date(aestTime);
console.log('AEST time: '+aestTime.toLocaleString())

var asiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Shanghai"});
asiaTime = new Date(asiaTime);
console.log('Asia time: '+asiaTime.toLocaleString())

var usaTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});
usaTime = new Date(usaTime);
console.log('USA time: '+usaTime.toLocaleString())

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString

这篇关于在JavaScript中将日期转换为另一个时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆