AntonIva
AntonIva

Reputation: 608

moment.js isValid for a string in JSON date format

I have a date in string format as

var addedDate = "2016-10-03T00:00:00.000Z";

How to check if this string

After doing some research I see that I can check using isValid method in Moment.js

moment(addedDate, formatToCheck).isValid(); 

how should look "formatToCheck" format

formatToCheck=???

Upvotes: 2

Views: 3053

Answers (2)

Akshatha Nayak
Akshatha Nayak

Reputation: 1

var addedDate = "2016-10-03T00:00:00.000Z"; Then how to assign value for year month and day from he above string in json format like Year: value, month:value, day: value

Upvotes: 0

Geeky
Geeky

Reputation: 7496

You can do something like this

moment('2016-10-03T00:00:00.000Z', 'YYYY-MM-DD').isValid(); 

To check the full format,i guess you can do something like this

moment('2016-10-03T00:00:00.000Z', 'YYYY-MM-DD HH:mm:ms').isValid();

Upvotes: 2

Related Questions