Checks if the given string is valid in the simplified extended ISO format (ISO 8601).
Date
constructor to create a Date
object from the given string.Date.prototype.valueOf()
and Number.isNaN()
to check if the produced date object is valid.Date.prototype.toISOString()
to compare the ISO formatted string representation of the date with the original string.const isISOString = val => {
const d = new Date(val);
return !Number.isNaN(d.valueOf()) && d.toISOString() === val;
};
isISOString('2020-10-12T10:10:10.000Z'); // true
isISOString('2020-10-12'); // false
JavaScript, Date
Returns the ISO format of the given number of seconds.
JavaScript, Date
Converts a date to extended ISO format (ISO 8601), including timezone offset.
JavaScript, Date
Returns the human-readable format of the given number of milliseconds.