I want to change a format of a date and time string. But moment.js changes timezone to my system timezone (+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"
How to just change a format without changing timezone?
I want to change a format of a date and time string. But moment.js changes timezone to my system timezone (+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"
How to just change a format without changing timezone?
Share Improve this question asked Sep 6, 2013 at 11:51 GreenGreen 30.8k61 gold badges163 silver badges253 bronze badges2 Answers
Reset to default 5See moment issue #887, directly regarding this. It may be easier in a future version, but the current workaround is as follows:
var input = "2013-09-20 23:59:59 +0100";
var m = moment(input).zone(input);
m.format("DD-MM-YYYY HH:mm:ss ZZ")
In 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");
Doc-API