我使用date('w', timestamp)和date('w', timestamp)知道这一天,date('n', timestamp)几个月,等等.
现在我正在使用datetime,我想知道从日期时间获得一天,一个月等的等效函数.
PS:我知道我可以UNIX_TIMESTAMP()在SQL查询中使用,但我更喜欢在代码中避免使用时间戳.
Kin*_*nch 99
将DateTime与DateTime :: format()一起使用
$datetime = new DateTime($dateTimeString);
echo $datetime->format('w');
Run Code Online (Sandbox Code Playgroud)
etu*_*rdu 24
查看手册:http://www.php.net/manual/en/datetime.format.php
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
Run Code Online (Sandbox Code Playgroud)
将输出: 2000-01-01 00:00:00