javascript - Parsing formatted date with moment js -
i'm formatting incoming date 2016-11-10t21:59:53.000+0000
moment js as:
myservice.getdate(id) .then(function (data) { data.occureddate = moment.utc(new date(data.occureddate)).format('dd mmm yyyy h:mm a'); };
the output result looks like: 10 nov 2016 10:00 pm
now i'm trying parse date string, unfortunately attempts unsuccessful
console.log(new date(obj.occureddate)) console.log(new date(obj.occureddate).tostring()) console.log(date.parse(obj.occureddate)) console.log(new date(date.parse(obj.occureddate))) console.log(new date(date.parse(obj.occureddate)).tostring()) invalid date invalid date nan invalid date invalid date
could explain me i'm doing wrong?
thanks in advance.
as parsing non standard format, specify format. use moment's todate()
method plain js date object:
moment.utc(obj.occureddate, 'dd mmm yyyy h:mm a').todate();
sidenode
using moment.utc(new date(data.occureddate))
doesn't make sense. parse string.
Comments
Post a Comment