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

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this