Last active
August 29, 2015 14:04
-
-
Save dannyid/d808600aabb6d967fe5d to your computer and use it in GitHub Desktop.
Format Time
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
function formatTime(time) { | |
//time needs to be a Date object like 'new Date()' | |
var h = time.getHours(), | |
m = time.getMinutes(), | |
s = time.getSeconds(), | |
m = (m < 10 ? '0' : '' ) + m, | |
s = (s < 10 ? '0' : '' ) + s, | |
formattedTime = (h > 12 ? h - 12 : (h === 0 ? h + 12 : h)) + ':' + m + ':' + s + (h >= 12 ? ' PM': ' AM'); | |
return formattedTime; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment