技术社区 / 行业技术交流 / php获取当前日期的四种方法

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

置顶
--
2024-03-12 15:07:23 阅读 7561 评论 0

方法一:使用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());

评论(0)

消灭零回复,来发表第一条评论吧
咨询热线
15899929162 0769-82882996 400-6116-696
微信扫码咨询
返回顶部