php获取当前日期的四种方法

置顶 148
· 2024-03-12 15:07:23

方法一:使用PHP内置函数date()

$currentDate = date("Y-m-d");

方法二:使用PHP内置函数getdate()

$currentDateArray = getdate();
$currentDate = $currentDateArray["year"] . "-" . $currentDateArray["mon"] . "-" . $currentDateArray["mday"];

 

方法三:使用PHP内置类DateTime

$currentDateObject = new DateTime();
$currentDate = $currentDateObject->format("Y-m-d");

方法四:使用PHP内置函数strftime()

$currentDate = strftime("%Y-%m-%d", time());