I have an input on my website and my timezone is utc+2h:
var startDate = "01/01/2019"
result = moment(startDate).utc().format();
alert(result);
This gives back 2018-12-31T23:00:00+00:00, but what I need for the api is 2019-01-01T00:00:00+00:00 (first of month at utc timezone), so what i need is more or less set the input timezone to already be utc. Is there a way to do this with Moment.js? (else I could do the whole thing manually of course)
I have an input on my website and my timezone is utc+2h:
var startDate = "01/01/2019"
result = moment(startDate).utc().format();
alert(result);
This gives back 2018-12-31T23:00:00+00:00, but what I need for the api is 2019-01-01T00:00:00+00:00 (first of month at utc timezone), so what i need is more or less set the input timezone to already be utc. Is there a way to do this with Moment.js? (else I could do the whole thing manually of course)
Share Improve this question asked Aug 12, 2018 at 8:25 solairesolaire 5055 silver badges25 bronze badges2 Answers
Reset to default 3You can use moment timezone
You can set default time zone to UTC ref
By default, moment objects are created in the local time zone. Local time zone - it's a time zone which is set in a browser or on your node.js server.
To change the default time zone, use moment.tz.setDefault with a valid time zone.
moment.tz.setDefault("America/New_York");
OR
You can explicitly set timezone, when parsing date:
m = moment.tz("2013-11-18 11:55", "Europe/Berlin");
And convert it to timezone you require later, like:
m.tz("UTC");
Hope this helps :)
This seems to give me the right result:
var startDate = "01/01/2019"
result = moment.utc(startDate, "DD-MM-YYYY").format();
alert(result);
//2019-01-01T00:00:00+00:00