一個簡單日曆

基本點:

    (1)每個月的日期

        const long dayarr[12] = {31,28/29,31,30,31,30,31,31,30,31,30,31};

 

    (2)確定閏年

       isleapyear --> (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))

    

    (3)確定最大天數

        ((month-- == 2 && isleapyear(year)) ? dayarr[month] + 1 : dayarr[month])

 

    (4)日期對應的周下標(0~6)

            long getweekindex(long date)
            {        
                long year  = GETYEAR(date);
                long month  = GETMONTH(date);
                if(month == 1 || month == 2)
                {
                    month += 12;
                    --year;
                }
                return ((date%            100) + 2 * month + 3 * (month + 1)/5 +year + year/4 - year/100 + year/400 + 1)%7;
            } 

        

    (5)其他細節、顯示效果等

            wKiom1MJo4bhWoOmAAHvV8X_2Lc213.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章