Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Created February 9, 2020 00:08
Show Gist options
  • Save joe-oli/c54b630366eb9209e7cddc814ec8e02f to your computer and use it in GitHub Desktop.
Save joe-oli/c54b630366eb9209e7cddc814ec8e02f to your computer and use it in GitHub Desktop.
is string a valid date in javascript js
//*** Is STRING a Valid Date? ***
approach: check if .getTime is equal to itself; WTF?
because if date is invalid, it will return NaN for .getTime();
You can a) check isNaN(.getTime()) or (b) NaN is never equal to itself;
; i.e. return .getTime() === .getTime() is true, if valid date; false if not date - haha WTF indeed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment