【发布时间】:2011-05-22 11:30:12
【问题描述】:
我在 mysql '2010-12-08 16:12:12' 中有一个日期时间值
我想使用PHP 获取到该日期的秒数,
所以基本上 PHP 相当于 mysql :
TIME_TO_SEC(TIMEDIFF('2010-12-08 16:12:12',now()))
【问题讨论】:
我在 mysql '2010-12-08 16:12:12' 中有一个日期时间值
我想使用PHP 获取到该日期的秒数,
所以基本上 PHP 相当于 mysql :
TIME_TO_SEC(TIMEDIFF('2010-12-08 16:12:12',now()))
【问题讨论】:
<?php
$date1 = new DateTime("2010-12-08 16:12:12");
$now = new DateTime();
$difference_in_seconds = $date1->format('U') - $now->format('U');
->format('U') 将其转换为 unix 时间戳。
【讨论】:
嗯?这些函数来自mysql ...
对于 PHP,您可以使用 strtotime 替换它
$diff = strtotime('2010-12-08 16:12:12')-time();
【讨论】:
time() 大于数据库中的旧时间戳行
试试
$time_diff = time() - strtotime('2010-12-08 16:12:12');
【讨论】:
使用 mktime()
【讨论】: