Skip to content

Instantly share code, notes, and snippets.

@cdmo
Last active December 21, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdmo/6280898 to your computer and use it in GitHub Desktop.
Save cdmo/6280898 to your computer and use it in GitHub Desktop.
formatting time
// Shape the timestamp just so
function formatTime(timestamp){
var time = new Date(timestamp * 1000);
var hours = time.getHours()-(time.getTimezoneOffset()/60); // assuming behind the meridian
var minutes = time.getMinutes();
minutes = minutes < 10 ? '0' + minutes : minutes;
hours = hours > 12 ? hours - 12 : hours;
if (hours === 0){
return '12:' + minutes + 'A.M.';
} else if (hours < 12) {
return hours + ':' + minutes + ' A.M';
} else {
return (hours-12) + ':' + minutes + ' P.M';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment