更新时间:2023-01-31 14:49:50
简单地:
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 *** 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