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)
You 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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With