php date生成相对日期表达式

   2024-10-09 7030
核心提示:在 PHP 中,可以使用 strtotime() 函数来生成相对日期表达式。以下是一些示例:// 获取当前日期$currentDate = date('Y-m-d

在 PHP 中,可以使用 strtotime() 函数来生成相对日期表达式。以下是一些示例:

// 获取当前日期$currentDate = date('Y-m-d');// 获取明天的日期$tomorrow = date('Y-m-d', strtotime('+1 day'));// 获取昨天的日期$yesterday = date('Y-m-d', strtotime('-1 day'));// 获取下个月的日期$nextMonth = date('Y-m-d', strtotime('+1 month'));// 获取上个月的日期$lastMonth = date('Y-m-d', strtotime('-1 month'));// 获取一周后的日期$nextWeek = date('Y-m-d', strtotime('+1 week'));// 获取一周前的日期$lastWeek = date('Y-m-d', strtotime('-1 week'));

通过使用 strtotime() 函数,可以轻松地生成各种相对日期表达式,从而方便地操作日期。

 
举报打赏
 
更多>同类维修大全
推荐图文
推荐维修大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号