Created
February 9, 2020 00:08
-
-
Save joe-oli/c54b630366eb9209e7cddc814ec8e02f to your computer and use it in GitHub Desktop.
is string a valid date in javascript js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*** 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