How to find a start date & end date of any given year & month

前端 未结 8 1438
庸人自扰
庸人自扰 2021-01-04 05:18

I have problem in php find start date & end date of month & year , when i know the year and month ?

ex:

input - > year = 2011 , month = 0         


        
8条回答
  •  有刺的猬
    2021-01-04 06:09

    PHP may have a more elegant way of doing this, but if you want a generic algorithm, here's what you need to do...

    All months other than February have a fixed number of days. February has 29 only when it's a leap year. Here are the rules to check if it's a leap year:

    1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
    2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
    3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
    4. The year is a leap year (February has 29 days).
    5. The year is not a leap year (February has 28 days).

提交回复
热议问题