zrobiłem coś simular na blogu, aby zobaczyć, jak długo im razem z moją dziewczyną: P http://daystogether.blogspot.com/ i to jest, jak to zrobiłem:
// *****Set the unit values in milliseconds.*****
var msecPerMinute = 1000 * 60;
var msecPerHour = msecPerMinute * 60;
var msecPerDay = msecPerHour * 24;
// *****Setting dates*****
var today = new Date();
var startDate = new Date('10/27/2011 11:00:00');
// *****Calculate time elapsed, in MS*****
var interval = today.getTime() - startDate.getTime();
var days = Math.floor(interval/msecPerDay);
interval = interval - (days * msecPerDay);
var weeks = 0;
while(days >= 7)
{
days = days - 7;
weeks = weeks + 1;
}
var months = 0;
while(weeks >= 4)
{
weeks = weeks - 4;
months = months + 1;
}
// Calculate the hours, minutes, and seconds.
var hours = Math.floor(interval/msecPerHour);
interval = interval - (hours * msecPerHour);
var minutes = Math.floor(interval/msecPerMinute);
interval = interval - (minutes * msecPerMinute);
var seconds = Math.floor(interval/1000);
BTW to tylko javascript, bez jQuery;)
Sprawdź ten link http: // stackoverflow .pl/questions/2609513/jquery-calcul-day-differn CE-in-2-daktyla otaczaniem –
wygląd [o] [1] i [o] [2] [1]: http://stackoverflow.com/questions/327429/whats- najlepsza metoda obliczania różnicy dat w javascript [2]: http://stackoverflow.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form –
nie potrzebujesz też dni? – redmoon7777