溫馨提示×

php date生成相對日期表達(dá)式

PHP
小樊
82
2024-06-18 17:42:54
欄目: 編程語言

在 PHP 中,可以使用 strtotime() 函數(shù)來生成相對日期表達(dá)式。以下是一些示例:

// 獲取當(dāng)前日期
$currentDate = date('Y-m-d');

// 獲取明天的日期
$tomorrow = date('Y-m-d', strtotime('+1 day'));

// 獲取昨天的日期
$yesterday = date('Y-m-d', strtotime('-1 day'));

// 獲取下個(gè)月的日期
$nextMonth = date('Y-m-d', strtotime('+1 month'));

// 獲取上個(gè)月的日期
$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() 函數(shù),可以輕松地生成各種相對日期表達(dá)式,從而方便地操作日期。

0