Skip to content


php5.2.14中strtotime格式时间戳错误引起日期混乱

状况是用smarty version 2.6.5-dev格式的时间在线上服务器显示时间不对.

  1. {$smarty.now|date_format:"%Y/%m/%d %H:%M"}

会显示成 5068/08/16 10:30

检查smarty/plugins/shared.make_timestamp.php
strtotime函数在不同版本下会有不同返回结果

  1. $time = strtotime($string);

编写代码确认
code:

  1. <?
  2. echo time();
  3. echo '---';
  4. var_dump(strtotime(time()));
  5. ?>

win php5.3.1
result:
1313465002—bool(false)

linux php5.2.14
result:
1313465026—int(96457670026)

“96457670026”?这个就是引起错误的原因.

修改下smarty/plugins/shared.make_timestamp.php
解决问题

  1. if (is_numeric($string) && $string != -1)
  2.         return $string;
  3.     $time = strtotime($string);
  4.     if (is_numeric($time) && $time != -1)
  5.         return $time;

Posted in PHP.

Tagged with , , , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.