Timestamps of start and end of month

后端 未结 7 1859
独厮守ぢ
独厮守ぢ 2020-12-03 17:04

How can one get the timestamps of the first and last minutes of any month using PHP?

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 17:44

    Use mktime for generating timestamps from hour/month/day/... values and cal_days_in_month to get the number of days in a month:

    $month = 1; $year = 2011;
    $firstMinute = mktime(0, 0, 0, $month, 1, $year);
    $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    $lastMinute = mktime(23, 59, 0, $month, $days, $year);
    

提交回复
热议问题