Home  >  Article  >  Backend Development  >  php 如何避免 1970前时间 时间戳失效了

php 如何避免 1970前时间 时间戳失效了

WBOY
WBOYOriginal
2016-06-13 13:31:431047browse

php 如何处理 1970前时间 时间戳失效了
最近涉及到做处理古代日期, 时间戳不能用了啊 date mktime 小于1970 就不行了

比如 1885-11-25 与 1901-01-12 日期差 就没法算了  

求高手帮助

------解决方案--------------------

PHP code
mysql_connect();
$d1 = '1901-01-12';
$d2 = '1885-11-25';
$rs = mysql_query("select TO_DAYS('$d1')-TO_DAYS('$d2')");
list($t) = mysql_fetch_row($rs);
echo $t;
<br><font color="#e78608">------解决方案--------------------</font><br>
<br>
PHP code
date_default_timezone_set('Asia/Hong_Kong');

$datetime1 = new DateTime('1885-11-25');
$datetime2 = new DateTime('1901-01-12');

$interval = $datetime1->diff($datetime2);
print_r($interval); <div class="clear">
                 
              
              
        
            </div>
Statement:
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