The easiest way to compare dates in javascript is to first convert it to a Date object and then compare these date-objects. Below you find an object with three functions:
I have date time in a particular timezone as a string and I want to convert this to the local time. But, I don't know how to set the timezone in the Date object. For example, I have Feb 28 2013 7:...
In my Javascript app I have the date stored in a format like so: 2011-09-24 Now when I try using the above value to create a new Date object (so I can retrieve the date in a different format), the...
new Date().getTime() Functionally equivalent to new Date().valueOf() Date.now() Functionally equivalent to the 2 methods above As mentioned in the comments and MDN links, Date.now() is not supported in Internet Explorer 8. So if IE 8 compatibility is a concern you should use new Date().valueOf() at the cost of slightly diminished code readability.
Detecting a Date type object (as opposed to a plain Object or a string) and validating an object you expect to be a Date are two different tasks. There are a number of situations where the input to your function could be one of a number of different data types. In my case, I can trust that any Date object I get is valid (it's not coming straight from a client) If validating is a concern, here ...