[英]PHP strtotime returning always midnight
I'm having a weird problem. 我有一个奇怪的问题。 When I do strtotime it's not considering the hours part of the original date, and it's always returning midnight. 当我做strtotime时,它没有考虑原始日期的小时部分,并且它总是在午夜返回。 I tried to research but I couldn't find anything specific. 我试图研究,但我找不到具体的东西。
Is there something I'm missing? 有什么我想念的吗?
$original_date = "2015-08-07 02:00:00";
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week +1 week", strtotime($original_date)));
It returns $next_date
as 2015-08-14 00:00:00
它返回$next_date
作为2015-08-14 00:00:00
Try this, add time which you want to retrieve in next date,. 试试这个,添加你想在下一个日期检索的时间。
$original_date = "2015-08-07 02:00:00";
echo $next_date = date('Y-m-d H:i:s', strtotime("monday this Week 02:00:00 +1 week", strtotime($original_date)));
monday this week +1 week
assumes you're looking for midnight of the monday of the week of the passed in time. monday this week +1 week
假设您正在寻找传递时间周一周一的午夜。 If you want to preserve the hours part of the time, then you can append it to your date
format because it should always be the same as in $original_date
如果你想保留部分时间,那么你可以将它附加到你的date
格式,因为它应该始终与$original_date
相同
date('Y-m-d ' . date('H:i:s', strtotime($original_date)), strtotime("monday this Week +1 week", strtotime($original_date)));
When you use monday
in strtotime
you're resetting the time back to 00:00:00. 当您在strtotime
使用monday
,您将时间重置为00:00:00。 You will have to explicitly pass the time in either your date
or strtotime
to get your desired behavior. 您必须在date
或strtotime
明确传递时间以获得所需的行为。 See this same question for a similar issue. 对于类似问题,请参阅同一问题。
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week +1 week " . date('H:i:s', strtotime($original_date)), strtotime($original_date)))
$date = strtotime('2018-08-14 02:00:00');
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week 02:00:00 +1 week", $date)); // 2018-08-20 02:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.