Skip to content

Instantly share code, notes, and snippets.

@dashawk
Last active July 26, 2017 07:01
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 dashawk/d6eb814b8dc9f59397d03e521866f0cd to your computer and use it in GitHub Desktop.
Save dashawk/d6eb814b8dc9f59397d03e521866f0cd to your computer and use it in GitHub Desktop.
Manipulate Dates in Javascript
/**
* Returns the hour difference between two dates
*/
function getHours(startDate, endDate) {
return Math.floor(Math.abs(startDate - endDate) / 3.6e6);
}
/**
* Returns the current hour in 12-hours format
*/
function toAmPm(date) {
return (date.getHours() + 24) % 12 || 12;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment