简体   繁体   中英

PHP's function date() not working properly? (unexpected output)

I've noticed that one of my scripts that depend on the function date() fell into an infinite loop. While investigating the cause of this, I came up with a very simple an surprising test:

<?php
echo (date("Y-m-d H:i:s",1330221136)."\n\n");
echo (date("Y-m-d H:i:s",1330222036)."\n");

Since the first timestamp is smaller than the second, the first line was supposed to return an earlier datetime. However the out put for the code above is:

2012-02-25 23:52:16 

2012-02-25 23:07:16

Does anybody know about any malfunctioning of the function date() in PHP 5.3?

This could legitimately happen if the clocks were turned one hour backwards at exactly 00:00 local time. So:

  1. Your code has a bug, because it does not allow for the possibility of this happening
  2. It seems that in your local time zone DST ended on 2012-02-26 00:00 (local time)
  3. Which lets us know that you are located in Brasil (props to Fluffeh for finding out!)

A copy/paste to my installation gives this as a result:

2012-02-26 02:52:16
2012-02-26 03:07:16

That seems fine to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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