php 获取指定月份的开始结束时间戳。
<?php /** * * 获取指定年月的开始和结束时间戳 * * @param int $year 年份 * @param int $month 月份 * @return array(开始时间,结束时间) */ function getMonthBeginAndEnd($year = 0, $month = 0) { $year = $year ? $year : date('Y'); $month = $month ? $month : date('m'); $d = date('t', strtotime($year . '-' . $month)); return ['begin' => strtotime($year . '-' . $month), 'end' => mktime(23, 59, 59, $month, $d, $year)]; } /** * 获取指定时间戳所在的月份的开始时间戳和结束时间戳 * * @param int $timestamp * @return array(开始时间,结束时间) */ function getMonthBeginAndEnd($timestamp = 0) { $timestamp = $timestamp ? $timestamp : time(); $year = date('Y', $timestamp); $month = date('m', $timestamp); $d = date('t', strtotime($year . '-' . $month)); return ['begin' => strtotime($year . '-' . $month), 'end' => mktime(23, 59, 59, $month, $d, $year)]; }