function dateSubtraction(d1y:int,d1m:int,d1d:int, d2y:int,d2m:int,d2d:int): Number {
return (cal2JD(d2y, d2m, d2d, 0, 0, 0) -
cal2JD(d1y, d1m, d1d, 0, 0, 0));
}
function cal2JD(year,month,day,hour,minute,second) {
//
// Compute the Julian Date for a given day, month, year
//
var a = 0; var b = 0;
var gregorian = false;
if (month < 3) { year -= 1; month += 12; }
// Check if date is in the Gregorian calendar.
if (year > 1582) { gregorian = true; }
if (year==1582) {
if (month > 10) { gregorian = true; }
if ((month==10)&&(day>=15)) { gregorian = true; }
}
if (gregorian==true) { a = intw(year/100); b = 2-a+intw(a/4); }
return (intw(365.25 * year) + intw(30.6001 * (month + 1))
+ day + (hour/24) + (minute/1440) + (second/86400)
+ 1720994.5 + b);
}
function intw(num) {
return parseInt("0" + num,10); // INT function (like TRUNC).
}
trace(dateSubtraction(2010, 11, 1, 2010, 11, 8));
// 7 |
No comments:
Post a Comment