尝试将 MysQl 时间戳转换为 Time Ago 时无法解析时间字符串
Failed to parse time string when trying to convert MysQl Timestamp to Time Ago
我正在尝试将 MysQl 时间戳转换为显示 time ago
,但出现此错误
Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct(): Failed to parse time string (1493324845)
脚本
<?php
//convert timestamp to time ago
$start_date = new DateTime();
$time = strtotime($streamuser['Datetime']);
$dbDate = new DateTime($time);
$currDate = new DateTime();
$interval = $currDate->diff($dbDate);
?>
<span><?php echo $interval->d." days ".$interval->h." hours";?></span>
MysQl 时间戳格式为 2017-04-27 22:27:25
我做错了什么?
我收到错误是因为我试图解析 date_diff() 需要 datetime 对象的字符串。这对我有用:
<?php
//convert timestamp to time ago
$dbDate =$streamuser['Datetime'];
$date = new DateTime($dbDate);
$now = new DateTime();
?>
<span style="font-size:smaller;">
<?php echo $date->diff($now)->format("%d days, %h hours and %i minutes");?> ago</span>
我正在尝试将 MysQl 时间戳转换为显示 time ago
,但出现此错误
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1493324845)
脚本
<?php
//convert timestamp to time ago
$start_date = new DateTime();
$time = strtotime($streamuser['Datetime']);
$dbDate = new DateTime($time);
$currDate = new DateTime();
$interval = $currDate->diff($dbDate);
?>
<span><?php echo $interval->d." days ".$interval->h." hours";?></span>
MysQl 时间戳格式为 2017-04-27 22:27:25
我做错了什么?
我收到错误是因为我试图解析 date_diff() 需要 datetime 对象的字符串。这对我有用:
<?php
//convert timestamp to time ago
$dbDate =$streamuser['Datetime'];
$date = new DateTime($dbDate);
$now = new DateTime();
?>
<span style="font-size:smaller;">
<?php echo $date->diff($now)->format("%d days, %h hours and %i minutes");?> ago</span>