Skip to content

Instantly share code, notes, and snippets.

@jdrew1303
Forked from addyosmani/timeUntil.js
Last active August 29, 2015 14:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jdrew1303/0b4f063313ff19fb83d0 to your computer and use it in GitHub Desktop.
var timeUntil = {
inHours: function(d1, d2) {
return parseInt((d2.getTime()-d1.getTime())/(24*3600), 10);
},
inDays: function(d1, d2) {
return parseInt((d2.getTime()-d1.getTime())/(24*3600*1000), 10);
},
inWeeks: function(d1, d2) {
return parseInt((d2.getTime()-d1.getTime())/(24*3600*1000*7), 10);
},
inMonths: function(d1, d2) {
return (d2.getMonth()+12*d2.getFullYear())-(d1.getMonth()+12*d1.getFullYear());
},
inYears: function(d1, d2) {
return d2.getFullYear()-d1.getFullYear();
}
}
var endDate = new Date("July, 20, 2012");
var startDate = new Date();
console.log(timeUntil.inDays(startDate,endDate));
console.log(timeUntil.inHours(startDate,endDate));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment