Like this:
const RFC_3339 = 'YYYY-MM-DDTHH:mm:ss';
moment.utc().format(RFC_3339);
I need the timestamp to have a 'Z' at the end. Is there a better way than just +'Z'?
It should match the python code on the backend:
RFC_3339_FMT = "%Y-%m-%dT%H:%M:%SZ"
To get the current date and time, just call javascript moment() with no parameters like so: var now = moment(); This is essentially the same as calling moment(new Date()) . Unless you specify a time zone offset, parsing a string will create a date in the current time zone.
format(); moment(). format(String); This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.
_i will never be a moment object. _i can also be undefined, in the case of creating the current moment with moment() . _d is the instance of the Date object that backs the moment object. If you are in "local mode", then _d will have the same local date and time as the moment object exhibits with the public API.
You can simply use format().
As the docs says:
As of version 1.5.0, calling
moment#formatwithout a format will default tomoment.defaultFormat. Out of the box,moment.defaultFormatis the ISO8601 formatYYYY-MM-DDTHH:mm:ssZ.As of version 2.13.0, when in UTC mode, the default format will return
Zas the offset, instead of+00:00
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