Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q228 How do you calulate the Julian day number of a date?

irt.org | Knowledge Base | JavaScript | Date | Q228 [ previous next ]

Q228 How do you calulate the Julian day number of a date?

<SCRIPT LANGUAGE="JavaScript"><!--
function makeArray()    {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var accumulate    = new makeArray(  0, 31, 59, 90,120,151,181,212,243,273,304,334);
var accumulateLY  = new makeArray(  0, 31, 60, 91,121,152,182,213,244,274,305,335);

function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

function getJulian(day,month,year) {
    if (LeapYear(year))
        return (day + accumulateLY[month]);
    else
        return (day + accumulate[month]);
}

var today = new Date();

document.write('Julian day = ' + getJulian(today.getDate(),today.getMonth()+1,today.getYear));
//--></SCRIPT>

Feedback on 'Q228 How do you calulate the Julian day number of a date?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.