hi,
i need a program that calculates the number of days since the beginning of the year.
example: 335 would be dec 20,2001 (for the year 2001)
thanks
claudeb
Well, one way to do it simply is jsut to create an array which holds the number of days in each month.
var DateArray = new Array();
DateArray[0] = 31;
// etc
Then the next bits of code get the current month - this can be used as an index for this array. Then you add up the days before the current month, by adding together the elements 0 ---> currentMonth-1, then lastly add the current day, and there you have it. BB "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
or you could use this function... its kinda bulky, but it does alot...
//returns an array of seconds, minutes, hours, day, month, year, dayof week, day of year, daylight savings time boolean.
//in that order. function works fine for day except the day that ends day light savings time. on the hour between 2 am and 2am
//on that day it will still say that it is daylight savings time... this is a bug that i was unable to work out.
Date.prototype.localtime = function()
{
var x = new Array();
var n = 0;
x.push(this.getSeconds());
x.push(this.getMinutes());
x.push(this.getHours());
x.push(this.getDate());
x.push(this.getMonth()+1);
x.push(this.getFullYear());
x.push(this.getDay());
var feb = (!(x[5]%4) && !(!(x[5]%100) && (x[5]%400)))?29:28;
switch(x[4])
{
case 1:
n = x[3];
break;
case 2:
n = 31+x[3];
break;
case 3:
n = 31+feb+x[3];
break;
case 4:
n = 62+feb+x[3];
break;
case 5:
n = 92+feb+x[3];
break;
case 6:
n = 123+feb+x[3];
break;
case 7:
n = 154+feb+x[3];
break;
case 8:
n = 184+feb+x[3];
break;
case 9:
n = 215+feb+x[3];
break;
case 10:
n = 245+feb+x[3];
break;
case 11:
n = 276+feb+x[3];
break;
case 12:
n = 306+feb+x[3];
break;
}
x.push;
var s = "04"
var t = "01";
var m = new Date(s+"/"+t+"/"+x[5]+" 02:00:01"
if(m.getDay() != 0)
{
t = 8-m.getDay();
t = "0"+t;
m = new Date(s+"/"+t+"/"+x[5]+" 02:00:01"
}
s = "10";
t = "31";
var f = new Date(s+"/"+t+"/"+x[5]+" 02:00:01"
if(f.getDay() != 0)
{
t = 31-f.getDay();
t = "0"+t;
f = new Date(s+"/"+t+"/"+x[5]+" 02:00:01"
}
if((this > m) && (this < f))
{
x.push(1);
}
else
{
x.push(0);
}
return x;
} adam@aauser.com
This children is why we don't smoke crack - bJ. "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
This children, is why we don't smoke crack - bJ. "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.