各位看官 , 如果你们看到这个页面 , 那么很可能你们都受伤了........ 看到了还来得及....... [php] //第一个坑 , 使用last month 的时候 , 小心!!! 我有个同事就是这么被坑了... 碰巧那天他回家结婚...然后我去填坑......这里顺便祝他新婚快乐了...囧.... //当时间到了每年的 03-29 ~ 03-31的时候 , date('m',strtotime('last month')); // 输出的居然是 3 , 囧 , 卧槽.....这不科学.... date('m',strtotime('first day of last month')); // 输出是 2 //还有另外一个坑 strtotime(date("Y-m-01 00:00:00")); //有时候会出现意外情况...转换过来的时间比实际时间要慢了 8 小时 , 当所有php老鸟会不以为然的认为这是time_zone的设置问题的时候 , 其实你们都错了, 它其实还有一个要求(只不过很多人都没留意罢了): //time //The string to parse, according to the GNU » Date Input Formats syntax. Before PHP 5.0.0, microseconds weren't allowed in the time, since PHP //5.0.0 they are allowed but ignored. // 然后去看看 Date Input Formats , 我们的YYYY-mm-dd格式是否符合要求 $ LC_ALL=C TZ=UTC0 date Mon Mar 1 00:21:42 UTC 2004 $ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ' 2004-03-01 00:21:42Z $ date --iso-8601=ns | tr T ' ' # --iso-8601 is a GNU extension. 2004-02-29 16:21:42,692722128-0800 $ date --rfc-2822 # a GNU extension Sun, 29 Feb 2004 16:21:42 -0800 $ date +'%Y-%m-%d %H:%M:%S %z' # %z is a GNU extension. 2004-02-29 16:21:42 -0800 $ date +'@%s.%N' # %s and %N are GNU extensions. @1078100502.692722128 T.T , yyyy-mm-dd HH:ii:ss 并不符合要求 换回这个就可以了: strtotime(date("Y-m-01 00:00:00")."Z"); [/php]
php strtotime last year,php函数strtotime的坑爹场景 -- 你们被坑了吗?
最新推荐文章于 2023-06-15 11:12:41 发布