Google Output
eventObject.srcElement.getValue()="2015-06-17T08:30:40.000"
new Date(eventObject.srcElement.getValue())= Wed Jun 17 2015 14:00:40 GMT+0530 (India Standard Time)
new Date()= Wed Jun 17 2015 12:53:03 GMT+0530 (India Standard Time)
new Date(eventObject.srcElement.getValue()) <= new Date() false
Mozilla Output
- eventObject.srcElement.getValue()= "2015-06-17T08:30:00.000"
- new Date(eventObject.srcElement.getValue())= Date 2015-06-17T03:00:00.000Z
- new Date()= Date 2015-06-17T07:21:14.629Z
- new Date(eventObject.srcElement.getValue()) <= new Date() true
When I am trying to enter date through date picker its not allowing me to select current date with more than current time, however it should not allow when i give less than current time and it should allow more than current time. (This functionality is working fine in Chrome)
Thanks
This is, unfortunately, because the TC-39 committee messed up a bit when defining ECMAScript5's standard date/time format: They based it on ISO-8601, but said that having no timezone indicator on the string defaulted to GMT ("Z"). But in ISO-8601, no timezone indicator means local time.
They're fixing this in ECMAScript6, and so now we're in the unpleasant middle where some JavaScript engines implement the ES5 specification even with the error (Chrome, for example, as of this writing), and others implement the ES6 specification (Firefox, for example, as of this writing).
So the only way you can reliably parse that date via the
Date
object, cross-browser, is to add a timezone indicator to it so it's unambiguous. Here's a function that checks if the string has as timezone indicator and, if not, adds a Z so it will be treated as GMT and applies the timezone offset to make it local time again:Or of course, parse the string yourself, as the format is really simple. Or use a library like MomentJS to do it for you.