方法一:DateTime::createFromFormat
strtotime()
不适用dd/mm/yyyy
格式,因为/导致的歧义。
可以使用DateTime::createFromFormat
来解决此问题。
<?php
$subject = '13/7/2020 18:24:56.496';
$date = DateTime::createFromFormat('d/m/Y H:i:s.u', $subject);
// echo($date->format('Y-m-d'));
echo $date->getTimestamp();
方法二:date_create_from_format
<?php
$start = "2023-02";
// 转换为date类型
$date = date_create_from_format('Y-m', $start);
// 增加2个月
date_add($date, date_interval_create_from_date_string("+2 month"));
// 增加5天
date_add($date, date_interval_create_from_date_string("+5 days"));
// 格式化
echo date_format($date, 'Y-m-d H:i:s');
参考:
https://www.php.net/datetime.createfromformat
https://www.imooc.com/wenda/detail/570030
https://www.w3school.com.cn/php/func_date_create_from_format.asp