Gre*_*een 6 javascript datetime momentjs
我想更改日期和时间字符串的格式.但是moment.js会将时区更改为我的系统时区(+3):
// This is a string:
"2013-09-20 23:59:59 +0100"
// I want to change it to this:
"20-09-2013 23:59:59 +0100"
// This is what I do and what I get. 1 hour is added by force:
moment("2013-09-20 23:59:59 +0100").format("DD-MM-YYYY HH:mm:ss ZZ")
"21-09-2013 01:59:59 +0300"
Run Code Online (Sandbox Code Playgroud)
如何在不改变时区的情况下更改格式?
请参阅时刻问题#887,直接与此有关.在将来的版本中可能会更容易,但目前的解决方法如下:
var input = "2013-09-20 23:59:59 +0100";
var m = moment(input).zone(input);
m.format("DD-MM-YYYY HH:mm:ss ZZ")
Run Code Online (Sandbox Code Playgroud)
在 moment.js v-2.8.3 中:
var dateTime = "2014-12-09 13:59:59 +0930";
var parseDateTimeZone = moment.parseZone(dateTime).format("YYYY-MM-DDTHH:mm:ssZ");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5621 次 |
| 最近记录: |