Reputation: 8161
I have a problem when i worked with Jquery new Date
function.
My Jquery code -
alert(new Date('/2013' + " 12:30 am"));
if (!isNaN(new Date('/2013' + " 12:30 am"))) {
alert('true');
} else {
alert('false');
}
When i execute this code in Chrome
it's always return me true
, but on other browser like firefox it's give false
.
When alert
this jquery new Date('/2013' + " 12:30 am")
code -
In Chrome it's give - new Date('/2013' + " 12:30 am")
give - Tue Jan 01 2013 00:30:00 GMT+0530 (India Standard Time)
.
In Firefox it's give - Invalid Date
.
Why this code return different value in different browser?
Upvotes: 2
Views: 274
Reputation: 1762
In Firefox when you call new Date(string)
the static method Date.parse(string)
is called.
But the string format that you used is not supported in Firefox, take a look at the MDN documentation:
I don't know why Chrome accepts this format (I couldn't manage to find the official docs) but it's not cross-browser safe, I would suggest to use new Date (year, month, date, hours, minutes, seconds, ms)
that is standard and cross-browser safe
Hope this helps
Upvotes: 1