This is pretty well described in docs . But, they are long, so here are the features:
For some reason, the wayjs ISO 8601 definition is different from ECMAScript , so it is not built-in. The format is YYYY-MM-DDTHH:mm:ss.sssZ and it must be in UTC (this means Z ).
So, moment().utc() guarantees the correct time zone.
Then format it:
moment().utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
Z escaped with square brackets . We can do this safely because we forced UTC.
The remaining characters indicate different time elements in accordance with the format table.
You can also do what RobG said and use your own date object. If you start with a minute:
moment().toDate().toISOString( )
source share