Reputation: 1631
I just want to create a js date object from a given string.
Stringformat: yyyy,mm,dd
This is my script:
var oDate = new Date('2013,10,07');
console.log(oDate);
In Chrome, IE and FF I get a right date, but with Safari I just get NaN
.
Upvotes: 1
Views: 102
Reputation: 3440
You can use the Date
constructor:
new Date(year, month, day, hours, minutes, seconds, milliseconds)
You can fix this problem like this:
var s='2013,10,07';
var a = s.split(',');
var date = new Date(a[0],a[1]-1,a[2]);
But you must be sure that the date format is always the same as in your sample.
Upvotes: 1