strtotime返回'-1个月'的时间戳不正确 [英] strtotime returns incorrect timestamp for '-1 month'

查看:135
本文介绍了strtotime返回'-1个月'的时间戳不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CCK日期字段。在Mart(> = 29 Mar)结束时的strtotime将为strtotime('1个月')返回不正确的结果。

  //当前日期3月30日
$ time = strtotime(' - 1个月');
打印日期('m / d / Y',$ time);

任何想法?

解决方案

这是直观的,但是:

  03/30/2011  -  1个月= 02/30 / 2011 => 03/02/2011 

同样的原因:

  03/31/2011 + 1个月= 04/31/2011 => 05/01/2011 

没有办法我知道得到上个月/下个月的同一天使用 PHP的相对日期/时间格式


I've using CCK date field. strtotime at end of Mart (>=29 Mar) will return incorrect result for strtotime('1- month').

// Current date Mar 30
$time = strtotime('-1 month');
print date('m/d/Y', $time);

Any ideas ?

解决方案

This is counter intuitive, but:

03/30/2011 - 1 month = 02/30/2011 => 03/02/2011

For the same reason:

03/31/2011 + 1 month = 04/31/2011 => 05/01/2011

There is no way I know of to get "same day last / next month" using the relative date/time formats of PHP.

这篇关于strtotime返回'-1个月'的时间戳不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆