mktime(0,0,0,null, 1); // gives first day of current month
mktime(0,0,0,null, date('t')); // gives last day of current month
$lastMonth = strtotime('last month');
mktime(0,0,0,date('n', $lastMonth), 1); // gives first day of last month
mktime(0,0,0,date('n', $lastMonth), date('t', $lastMonth); // gives last day of last month
如果你只想获得一个字符串进行演示,那么你不需要 mktime :
date('Y-m-1'); // first day current month
date('Y-m-t'); // last day current month
date('Y-m-1', strtotime('last month')); // first day last month
date('Y-m-t', strtotime('last month')); // last day last month
2 回答
strtotime与relative time formats非常强大:
(这仅适用于PHP 5.3)
为了获得PHP <5.3中一个月的第一个和最后一个日期,您可以使用mktime和date的组合(
date('t')
给出该月的天数):如果你只想获得一个字符串进行演示,那么你不需要
mktime
:这是一周的第一天和最后一天的功能:
它也许可以适应月份,但我想得到我的答案! :)