I have a string with this format 2018-02-26T23:10:00.780Z
I would like to check if it's in ISO8601 and UTC format.
let date= '2011-10-05T14:48:00.000Z';
const error;
var dateParsed= Date.parse(date);
if(dateParsed.toISOString()==dateParsed && dateParsed.toUTCString()==dateParsed) {
return date;
}
else {
throw new BadRequestException('Validation failed');
}
The problems here are:
- I don't catch to error message
- Date.parse() change the format of string date to
1317826080000
so to could not compare it to ISO or UTC format.
I would avoid using libraries like moment.js