I have this problem with Safari not recognizing the date format 2012-01-03 (being 2012 January 3rd). I have the dates within an array and then I want to convert them to this format – Tuesday Jan 3
Works in Chrome, but Safari is throwing undefined undefined NaN.
Some code below…
(function() {
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
Date.prototype.getDayName = function() {
return days[this.getDay()];
};
Date.prototype.getMonthName = function() {
return months[this.getMonth()];
};
})();
var issues = ['2012-01-03', '2012-01-02', '2012-01-01', '2011-12-31'];
for (var i = 0; i < issues.length; i++) {
var d = new Date(issues[i]);
var date = d.getDate(),
weekday = d.getDayName(),
month = d.getMonthName();
day = weekday + ' ' + month + ' ' + date;
$('.datepicker').find('ul').append('<li class="issue_' + i + '">' + day + '</li>');
}
I only need this to work for Safari/Mobile Safari, so prefer not to use any js library.
Simple debugging shows you the error:
It does not like the date format. You can change it something like this:
or you can do a split and do it in a format all browsers support
http://jsfiddle.net/TveJU/