Last active
August 29, 2015 14:12
-
-
Save liddiard/90931f58b0746b31926b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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