Question

I have a date stored in variable like below

var date = moment(new Date()).valueOf();

I need to format it like below

CCYY-MM-DDThh:mm:ss[.sss]TZD

The Time Zone Definition is mandatory and MUST be either UTC (denoted by addition of the character 'Z' to the end of the string) or some offset from UTC (denoted by addition of '[+|-]' and 'hh:mm' to the end of the string).

I have tried like below

var required = moment.utc(date).format('CCYY-MM-DDThh:mm:ss[.sss]TZD')

But it is resulting like below

"CC14-06-03T07:59:15.sssT+00:003"

But the expected format examples are

UTC : 

1969-07-21T02:56:15Z

Houston time :

1969-07-20T21:56:15-05:00
Était-ce utile?

La solution

Just try with:

'YYYY-MM-DDThh:mm:ssZ'

Output:

2014-06-03T08:16:15+00:00 

moment.js format documentation

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top