Skip to content

Instantly share code, notes, and snippets.

@jdrew1303
Forked from addyosmani/timeUntil.js
Last active Aug 29, 2015
Embed
What would you like to do?
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