是否有办法确定这个月的28号是否已经过去?
例如,如果这一天是1月29日,我怎么能抓住1月28日,或者如果这一天是1月1日,我怎么能抓住12月28日?是否有一种方法来一行这在php strtotime()?
它有是一行吗?它有使用strtotime()
吗?
$date = new DateTime('2014-01-01');
if ($date->format('j') < 28) {
$date->modify('previous month');
}
$date->setDate($date->format('Y'), $date->format('n'), 28);
echo $date->format('Y-m-d');
try
$d = '2014-07-29';
if (date('d', strtotime($d)) > 28) {
$diff = date('d', strtotime($d)) - 28;
echo date('Y-m-d', strtotime($d.'-'.$diff.' day')); //2014-07-28 getting 1 day back date
}
这个怎么样:
$curDay = date('d');
$curMonth = date('m');
$curYear = date('Y');
$thisMonth = $curYear.'-'.$curMonth.'-28';
if ($curDay > 28) {
echo 'Last 28th was: '.$thisMonth;
}else{
echo 'Last 28th was: '.date('Y-m-d',strtotime('-1 month',strtotime($thisMonth)));
}
对不起,这不是一行-如果您使用当前日期可以完成,但寻找本月28日意味着有更多的事情要做。