javascript - Current day number - different computers, different days -
i´m using this function in about.com today number in year (ex: 226). i´m getting different results (correct , +1 day) in different computers, using this calculator i´m getting wrong +1 day value. using this one correct day number. computers tested have correct date, hour, timezone.
ex. 8 minutes past midnight, i´m getting correct day (226), before midnight day when supposed 225, getting 226.
i suppose function ok, problem should be?
thanks
you getting confused between client time , server time.. website..
http://mistupid.com/calendar/dayofyear.htm using javascript calculate day of year using following formula
var dayofyear = math.ceil((entereddate.gettime() - startofyear.gettime()) / one_day) + 1
however, second website (http://www.epochconverter.com/epoch/daynumbers.php) using server time calculate day of year.
updates number of days according utc time.
date.prototype.getdoy = function() { var onejan = new date(this.getfullyear(),0,1); return math.ceil((this - onejan) / 86400000); } function convertdatetoutc(date) { return new date(date.getutcfullyear(), date.getutcmonth(), date.getutcdate(), date.getutchours(), date.getutcminutes(), date.getutcseconds()); } var today = new date(); var = convertdatetoutc(today); var daynum = a.getdoy(); alert(a); alert(daynum);
Comments
Post a Comment