strtotime(date(y-m-01 00:00:00)); // 用来获得本月的第一天时间戳
在实际php strtotime应用中突然有一次碰到转换过来的时间比实际时间要慢了 8 小时!本以为是 php.ini中的
timezone 设置有误导致,巡查了一圈最后把问题锁定在了strtotime 函数上(linux服务器下往往会出问题,windows服务器返回的数据基本都是正确的)
仔细读了下php手册,发现第一个参数 time 有格式要求
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 的进一步跟进发现
$ 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
发现我们常用的格式 yyyy-mm-dd hh:ii:ss 并不符合要求。大致看了下,决定采用utc0 格式随将以上代码更新为以下代码
strtotime(date(y-m-01 00:00:00).z); // 用来获得本月的第一天时间戳
至此问题解决!
php strtotime应用总结:
我们在开发过程中有时候被系统的支持而忽略了一些细节。就如本例在windows平台下是不会有这问题,但php strtotime应用还是要按规范的走会好些。以避免出现这类问题。
http://www.bkjia.com/phpjc/445988.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/445988.htmltecharticlestrtotime(date(y-m-01 00:00:00)); // 用来获得本月的第一天时间戳 在实际php strtotime应用中突然有一次碰到转换过来的时间比实际时间要慢了 8 小时...