Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created April 1, 2016 06:20
Show Gist options
  • Save vishalbasnet23/3ccf96a6af4d9ecc570f5d6e94539a23 to your computer and use it in GitHub Desktop.
Save vishalbasnet23/3ccf96a6af4d9ecc570f5d6e94539a23 to your computer and use it in GitHub Desktop.
Safari fix for date NaN issue
function formatDate(createdDate) {
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];
var parsedDate = Date.parse(createdDate);
// alert(parsedDate);
var date = new Date(createdDate.replace(/\s/, 'T'));
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment