可能重复:
在PHP中是否有像$date->getMonthDays()或$date->getLastDayOfMonth()这样的函数来获取给定月份的天数(或最后一天的天数)?
$start = new DateTime('2012-02-01');
$end = clone $start;
// Interval = last day of the month minus current day in $start
$interval = $start->getLastDayOfMonth() - intval($start->format('j'));
$end->add(new DateInterval('P' . $interval . 'D'));编辑:谢谢,投票关闭了,这是重复的,很抱歉问.
发布于 2012-01-18 15:32:39
php date函数给出月中“t”的天数。
date("t");请参阅:http://php.net/manual/en/function.date.php
发布于 2012-01-18 15:34:30
上个月的约会很简单
echo date("Y-m-t", strtotime("-1 month") ) ;
echo date("Y-m-1", strtotime("-1 month") ) ;3月3日返回
2011-02-28
2011-02-1发布于 2012-01-18 15:34:11
t给出了当前月份的总天数。j给你一个月中的当前一天。
使用modify和datetime的format-ing中的一些减法,您可以到达月底。
$date = new DateTime();
$lastDayOfMonth = $date->modify(
sprintf('+%d days', $date->format('t') - $date->format('j'))
);https://stackoverflow.com/questions/8912780
复制相似问题