我在 mysql
中有一个日期时间值 '2010-12-08 16:12:12',
我希望使用 PHP
获取到该日期的秒数,
也就是说需要一个与 mysql
等价的 PHP
函数:
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()
大于数据库中旧的时间戳行。 - Egor尝试
$time_diff = time() - strtotime('2010-12-08 16:12:12');