简体   繁体   English

仅使用strtotime,本月第一天凌晨0点使用PHP?

[英]Using just strtotime, 0 am first day of this month in PHP?

echo mydate(strtotime('1 am first day of this month'));

Above works with result 2017-10-01 01:00:00 , but I have difficulty to do it for 0 am. 上面的结果为2017-10-01 01:00:00 ,但是我很难在凌晨0点做。 Neither 24am, 24pm, 0pm, first second works. 24am, 24pm, 0pm, first second24am, 24pm, 0pm, first second

Use midnight : 使用midnight

echo mydate(strtotime('midnight first day of this month'));

Demo 演示版

Better to use DateTime for date and time manipulations, 最好使用DateTime进行日期和时间操作,

$date = new DateTime('midnight first day of this month'); echo $date->format('Ymd H:i:s');

or if there is need to UnixTimestamp : $date->format('U'); 或者如果需要UnixTimestamp: $date->format('U'); date- $date->format('U'); or echo $date->getTimestamp(); echo $date->getTimestamp();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM