Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
Good snippet to see if string is a valid date. Returns bool
.
const IsValidDate = (string) =>
{
if (string === null)
{
return false
}
// If the date is valid then the getTime() method will always be equal to itself.
// If the date is Invalid then the getTime() method will return NaN which is not equal to itself.
let d = new Date(string);
let results = d.getTime() === d.getTime();
return results;
};