Last active
April 22, 2017 19:31
-
-
Save ShaneQi/afa833c5e9f0f0f2b36259b31033244b to your computer and use it in GitHub Desktop.
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
var date1 = new Date() | |
var date2 = new Date(2016, 10, 6); // Date(2016, 10, 6) is Nov. 6, 2016 | |
var data1_ms = date1.getTime(); | |
var data2_ms = date2.getTime(); | |
// Then, calculate the milliseconds difference between the two dates. | |
var difference_ms = date2_ms - date1_ms; | |
// Finally, convert the difference back to days in which we should | |
// divide the milliseconds by one day’s milliseconds: | |
var oneday = 1000 * 60 * 60 * 24; | |
// Math.ceil() makes the difference rational | |
var result = Math.ceil(differencems/one_day); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment