String is ISO formatted date

JavaScript, Date · Nov 29, 2020

Checks if the given string is valid in the simplified extended ISO format (ISO 8601).

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

More like this

  • Number of seconds to ISO format

    Returns the ISO format of the given number of seconds.

    JavaScript, Date · Oct 13, 2021

  • Check if date is valid

    Checks if a valid date object can be created from the given values.

    JavaScript, Date · Oct 20, 2020

  • Format duration

    Returns the human-readable format of the given number of milliseconds.

    JavaScript, Date · Oct 22, 2020