Home  >  Article  >  Backend Development  >  php 计算时间差的有关问题

php 计算时间差的有关问题

WBOY
WBOYOriginal
2016-06-13 13:12:16886browse

php 计算时间差的问题
第一次user这个用户上线的时间格式是:2012-07-18 09:07:56
我让他试用的时间是12天。这个时间是从他第一次上线开始算的

他第二次上线的时间格式是:2012-07-25 06:11:56

算一下他是否过期

算一下他还剩下多少试用时间 

用php实现 谢谢各位大虾,时间转换这块不清楚哎。

------解决方案--------------------
初始化为NULL
第一次上线,如果为NULL,设置为now() timestamp类型
第二次上线,如果不为NULL,取出时间,用PHP的函数 time() - $item['tm'] > 12*3600
------解决方案--------------------

PHP code
$d1 = new datetime('2012-07-18 09:07:56');
$d2 = new datetime('2012-07-25 06:11:56');
print_r($d2->diff($d1)); <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