Skip to content

Instantly share code, notes, and snippets.

@liddiard
Last active August 29, 2015 14:12
Show Gist options
  • Save liddiard/90931f58b0746b31926b to your computer and use it in GitHub Desktop.
Save liddiard/90931f58b0746b31926b to your computer and use it in GitHub Desktop.
// Takes a year, month, and day number and outputs a string in the format "Dec 05, 2012".
// 'month' input parameter starts with zero.
function convertDateToEnglishString(day, month, year) {
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
try {
var monthName = monthNames[month];
} catch (e) {
alert('Invalid date');
return;
}
if (day < 10)
day = '0' + day; // zero-pad the day
return monthName + ' ' + day + ', ' + year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment