使用Moment.js版本2.0.0+转换位置之间的特定日期和时间(Convert a specific date and time between locations using Moment.js

编程入门 行业动态 更新时间:2024-10-25 17:20:02
使用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+将代表纽约,纽约日期和时间的日期时间字符串更改为澳大利亚墨尔本?


我在StackOverflow上找到的其他答案已经过时或与我的用例略有不同。

convert this string '2016-04-28 09:30:00' to its Melbourne Australia equivalent

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

最满意答案

只是:

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

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

更多推荐

本文发布于:2023-08-05 06:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1430254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   日期   版本   时间   Moment

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!