简体   繁体   English

php strtotime问题,给出不正确的值?

[英]php strtotime problems, giving incorrect values?

I have this code: 我有以下代码:

$date = '2010-03-08 8:10:20'
$new_date  = date('Y-m-d H:i:s', strtotime($date . " +1 month"));
echo $new_date;

Btw, I already set 顺便说一句,我已经设定

date_default_timezone_set('Europe/London');

And the result is: 5 April 2010, 3 days missing. 结果是:2010年4月5日,缺少3天。 Why is it happen? 为什么会这样呢? I heard they are some bugs in strtotime? 我听说他们是strtotime中的一些错误? If thats the case, how to get a correct one? 如果是这样,如何获得正确的答案? I mean, is there another way to replace this: 我的意思是,还有另一种方法可以代替它:

$new_date  = date('Y-m-d H:i:s', strtotime($date . " +1 month")); // or +2, +3... +100

使用mktime函数:

$date = date ( 'Y-m-d H:i:s', mktime ( arguments ) + one_month_epoch_value) ) ; 

I do this: 我这样做:

date_default_timezone_set('Europe/London');

$date = '2010-03-08 8:10:20';
$new_date  = date('Y-m-d H:i:s', strtotime($date . " +1 month"));
echo $new_date;

and get 并得到

2010-04-08 08:10:20

so you've got some other issue. 所以你还有其他问题。

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

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