php获取前一小时、前一天、三天前、前一个月、三个月前、前一年的

2023-05-17  本文已影响0人  一位先生_
//php获取前一个小时的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-1 hour"));
//php获取前一天的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-1 day"));
//php获取三天前的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-3 day"));
//php获取前一个月的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-1 month"));
//php获取三个月前的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-3 month"));
//php获取前一年的时间:

$mtime= date("Y-m-d H:i:s", strtotime("-1 year"));

获取指定日期范围内的所有日期:

function prDates(
    $start,$end){$dt_start = strtotime($start);
    $dt_end = strtotime($end);
    while ($dt_start<=$dt_end){
        echo date('Y-m-d',$dt_start)."\n";
        $dt_start = strtotime('+1 day',$dt_start);
    }
}
prDates('2005-02-01','2005-02-05');
echo "----------\n";
··
上一篇 下一篇

猜你喜欢

热点阅读