var today = new Date();
var Christmas = new Date("12-25-2009");
var diffMs = (Christmas - today); // milliseconds between now & Christmas
var diffDays = Math.round(diffMs / 86400000); // days
var diffHrs = Math.round((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
alert(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes until Christmas 2009 =)");
Wednesday, June 3, 2009
JavaScripting to find the difference between dates in hours, minutes, & seconds
Here's another little bit of JavaScript that I've found handy recently. It will calculate the difference between two dates and present the results in days, hours, and minutes. For the purposes of this post, I'm using today and Christmas day as the days that I'm trying to find the difference between.
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment