Search code examples
node.jsmomentjsisodateformatdatetime

How to format iso date in nodeJS


Here is my code

var newDateObj2 = moment("2020-04-29T14:05:00.000Z").format('YY/MM/DD,HH:mm:ss.S');
console.log(newDateObj2);

Output 
20/04/29,19:35:00.0

Expected Output
20/04/29,14:05:00.0

Why 5.30 (h.mm) getting added in my final result, When i print

moment("2020-04-29T14:05:00.000Z")`=> Moment<2020-04-29T19:35:00+05:30>

How to get Output 20/04/29,14:05:00.0


Solution

  • You should trim the Z from the ISO date string or use the utc() function moment("2020-04-29T14:06:00.000Z").utc().format('YY/MM/DD,HH:mm:ss.S');