Last active
August 29, 2015 13:56
-
-
Save jonkemp/9257854 to your computer and use it in GitHub Desktop.
Take a date string and return it in a certain format.
This file contains 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
function pad(num) { | |
return (num < 10 ? '0' : '') + num; | |
} | |
function formatDateMonthDayYear(date) { | |
if (date) { | |
date = new Date(date); | |
} else { | |
date = new Date(); | |
} | |
return pad(date.getMonth() + 1) + | |
'/' + pad(date.getUTCDate()) + | |
'/' + date.getFullYear(); | |
} | |
function toISOString(date) { | |
if (date) { | |
date = new Date(date); | |
} else { | |
date = new Date(); | |
} | |
return date.getFullYear() + | |
'-' + pad(date.getMonth() + 1) + | |
'-' + pad(date.getDate()) + | |
'T' + pad(date.getHours()) + | |
':' + pad(date.getMinutes()) + | |
':' + pad(date.getSeconds()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment