PHP date 年份太大 结果就异常 请教如何解决

WBOY
Release: 2016-06-13 12:16:42
Original
988 people have browsed it

PHP date 年份太大 结果就错误 请问怎么解决?

本帖最后由 liyuan66 于 2015-03-24 17:31:03 编辑 echo date('Y-m-d H:i:s',3356676867);
错误结果:1940-04-08 11:46:11
正确为2076/5/14 18:14:27

请问怎么才能输出这样的答案。
------解决思路----------------------
對了,上貼沒有設置時區,所以不對。
<br />$dt = new DateTime([email&#160;protected]');  <br />$tz = timezone_open('Asia/SHANGHAI');  <br />$dt->setTimezone($tz);  <br />echo $dt->format('Y-m-d H:i:s'); // 2076-05-14 18:14:27<br />
Copy after login

------解决思路----------------------


xu大说的没错,碰到问题多看看手册
如果有需求,你可以自行编写一个递归函数,当时间大于date()函数上限时,减去4年的秒数,进入有效范围计算出结果后,再把减过的多少个4年加回去
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template