Last active
July 26, 2017 07:01
-
-
Save dashawk/d6eb814b8dc9f59397d03e521866f0cd to your computer and use it in GitHub Desktop.
Manipulate Dates in Javascript
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
/** | |
* 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