This is pretty well covered in the docs. But, they're long, so here's the specifics:
For some reason, momentjs's definition of ISO 8601 differs from the ECMAScript one, so it isn't built in. The format is YYYY-MM-DDTHH:mm:ss.sssZ
and it must be in UTC (the Z
denotes this).
So, moment().utc()
makes sure the timezone is correct.
Then format it:
moment().utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
// 2015-02-02T21:38:04.092Z
The Z
is escaped with square brackets. We can do this safely because we forced UTC.
The rest of the characters denote various time elements according to the format table.
You could also do what RobG said and use the native date object. In case you are starting with a moment:
moment().toDate().toISOString( )
// 2015-02-02T21:40:06.395Z
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…