Jump to content

Time from X


cclloyd9785

Recommended Posts

Create a date object for each date. (There are many ways to do that.) For each object, use the getTime() method to get the number of milliseconds since midnight Jan 1, 1970. Subtract the first number from the second. Now you have the number of elapsed milliseconds between the dates. Use simple math to convert milliseconds to days. Example:

var d1 = new Date("August 10, 2011");var d2 = new Date();var elapsed = d2.getTime() - d1.getTime();var days = elapsed / (1000 * 60 * 60 * 24);var wholeDays = parseInt(days);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...