温馨提示×

php date生成相对日期表达式

PHP
小樊
84
2024-06-18 17:42:54
栏目: 编程语言
PHP开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在 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() 函数,可以轻松地生成各种相对日期表达式,从而方便地操作日期。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:php strtodate有哪些使用注意事项

0