Date : Date : Development JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Development » Date »

 

Date



<html>
<head>

</head>

<body>
<SCRIPT Language="JavaScript">
    function weekNo() {
        
        var totalDays = 0;
        
        now = new Date();
        years=now.getYear();
    
        var days = new Array(12)
        days[031;
        days[231;
        days[330;
        days[431;
        days[530;
        days[631;
        days[731;
        days[830;
        days[931;
        days[1030;
        days[1131;
 
        // is it a leap year
        //////////////////////////////////////////////////
        // has some year 2000 problem 
        // should check the year by dividing 4000
        //
        //////////////////////////////////////////////////
        if (Math.round(now.getYear()/4== now.getYear()/4) {
            days[129
        }else{
            days[128
        }
 
        // If this is January 
        if (now.getMonth() == 0) { 
            totalDays = totalDays + now.getDate();
        }else{
            var curMonth = now.getMonth();
            for (var count = 1; count <= curMonth; count++) {
                totalDays = totalDays + days[count - 1];
        }
        totalDays = totalDays + now.getDate();
    }

    var agt=navigator.userAgent.toLowerCase();
    
    if ((agt.indexOf("msie"!= -1&& (agt.indexOf("opera"== -1)) {
        var firstday=new Date("01/01/"+String(now.getYear())).getDay();
    }else {
        var firstday=new Date("01/01/"+String(1900+now.getYear())).getDay();
    }
    
    var diff=7-firstday+1;
    var week = Math.round((totalDays+diff-firstday)/7)return week;
}

document.write("Week "+weekNo()+" of "+years)

</SCRIPT>
</body>

</html>




           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Development
» Date