How can you save time by using the built in Date class?

后端 未结 5 1579
后悔当初
后悔当初 2021-01-07 11:57

The intention of this question is to gather solutions to date / time calculation using the built in Date class instead of writing long complicated functions.

I’ll wr

5条回答
  •  离开以前
    2021-01-07 12:31

    You can easily find out if a year was a leap year without coding all the exceptions to the rule by using the Date class. By subtracting one day from marts the 1st (requesting marts the 0th), you can find the number of days in February.

    Remember that month is zero-indexed so Marts being the 3rd month has index 2.

    function CheckIfYearIsLeapYear(year:uint):Boolean
    {
        return new Date(year, 2, 0).Date == 29;
    }
    

提交回复
热议问题