在PHP中获取给定月份和年份的开始和结束Unix时间戳
问题描述:
我想查找一个月第一天(例如2010年9月1日和0:00)和一个月最后一天(例如9月31日23:59)的时间戳.
I want to find the timestamp for the first day in a month (say September 1 2010 and 0:00) and the last day in a month (say September 31 23:59).
答
如果将这些日期作为字符串,则可以简单地使用 strtotime (),如果您只有部分信息,则可以使用 mktime().
If you have those dates as strings you can simply use strtotime(), if you have only partial information you can use mktime().
但是,9月只有30天;)
However, September only has 30 days ;)
示例:
$month = 9;
$year = 2010;
$first = mktime(0,0,0,$month,1,$year);
echo date('r', $first);
$last = mktime(23,59,00,$month+1,0,$year);
echo date('r', $last);