php怎样获取去年日期
1、首先要了解一下关于时间方面的函数:date() 和 strtotime()。date()函数:语法:date(format,timestamp);format:时间输出根据这个格式输出。timestamp:可选参数,使用的是 Unix 时间戳,不选默认使用当前环境时间。例子:$mytime= date("Y-m-d H:i:s");echo $mytime;效果如图所示:

3、现在使用上面两个组合获取去年的今天。首先使用strtotime(),获取是时间戳,然后使用date()函数格式化时间。代码:echo "今天日期:".date("Y-m-d H:i:s", strtotime("now"));echo "去年今天:".date("Y-m-d H:i:s", strtotime("-1 year"));效果如图:
