Skip to content

Instantly share code, notes, and snippets.

@SuperAL
Created September 18, 2017 08:53
Show Gist options
  • Select an option

  • Save SuperAL/12082d138a6375bf7488a3548a686992 to your computer and use it in GitHub Desktop.

Select an option

Save SuperAL/12082d138a6375bf7488a3548a686992 to your computer and use it in GitHub Desktop.
获取时间区间的跨度天数
// stackoverflow: https://stackoverflow.com/a/2627493/6339408
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12);
var secondDate = new Date(2008,01,22);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay))); // -> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment