使用Moment.js 2.0.0及更高版本在位置之间转换特定日期和时间 [英] Convert a specific date and time between locations using Moment.js version 2.0.0+
本文介绍了使用Moment.js 2.0.0及更高版本在位置之间转换特定日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Moment.js 2.0.0+将代表纽约,纽约日期和时间的日期时间字符串更改为澳大利亚墨尔本?
我在StackOverflow上发现的其他答案已经过时或与我的用例稍有不同.
convert this string '2016-04-28 09:30:00' to its Melbourne Australia equivalent
解决方案
简单地:
var s = moment.tz('2016-04-28 09:30:00', // input date time string
'YYYY-MM-DD HH:mm:ss', // format of input
'America/New_York') // time zone of input
.tz('Australia/Melbourne') // convert to another time zone
.format('YYYY-MM-DD HH:mm:ss'); // format output string
How do I change a date time string that represents a New York, New York date and time to Melbourne Australia using Moment.js 2.0.0+ ?
Other answers I found on StackOverflow were outdated or slightly different than my use case.
convert this string '2016-04-28 09:30:00' to its Melbourne Australia equivalent
解决方案
Simply:
var s = moment.tz('2016-04-28 09:30:00', // input date time string
'YYYY-MM-DD HH:mm:ss', // format of input
'America/New_York') // time zone of input
.tz('Australia/Melbourne') // convert to another time zone
.format('YYYY-MM-DD HH:mm:ss'); // format output string
这篇关于使用Moment.js 2.0.0及更高版本在位置之间转换特定日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文