1

I'm using moment js to deal with date and times in my project. When I'm trying to parse ISOstring to date format in moment js date and time are not coming properly.

This is my ISO string: '2016-04-27T18:30:00.000Z', I'm doing like this

moment('2014-02-27T18:30:00.000Z').format('YYYY-MM-DD HH:mm:ss');

I'm getting like this when running the above code "2014-02-28 00:00:00"

How to get the correct time?

Hari Kishan
  • 73
  • 3
  • 9

2 Answers2

4

You need to use another moment.js function, parseZone, since your date time format has time zone information.

moment.parseZone('2014-02-27T18:30:00.000Z').format('YYYY-MM-DD HH:mm:ss')
//moment.parseZone('2014-02-27T18:30:00.000Z').format('YYYY-MM-DD HH:mm:ss')
Arnau Lacambra
  • 130
  • 1
  • 7
1

Here we go:

moment().format('MMMM Do YYYY, h:mm:ss a'); // April 27th 2016, 4:00:27 pm
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Apr 27th 16
moment().format('YYYY [escaped] YYYY');     // 2016 escaped 2016
moment().format();                          // 2016-04-27T16:00:27+02:00

Hope it helps;)

Husni Salax
  • 1,968
  • 1
  • 19
  • 29