Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php sql时间戳可以';不显示正确的时间_Php_Mysql - Fatal编程技术网

Php sql时间戳可以';不显示正确的时间

Php sql时间戳可以';不显示正确的时间,php,mysql,Php,Mysql,我在我的网站上发了一篇帖子,想把时间stemp显示为“3分钟前” 但这是我的功能,它不能正常工作。 mysqltimestamp在更新后作为$time传递,如2018-04-15 09:00:02 这篇文章的制作时间仅在几分钟前,但在功能处理后的页面上显示的结果显示9小时前 请帮我显示正确的时间 public static function timeago($time){ $time=strtotime($time); $periods = array("second", "min

我在我的网站上发了一篇帖子,想把时间stemp显示为“3分钟前” 但这是我的功能,它不能正常工作。
mysql
timestamp
在更新后作为
$time
传递,如
2018-04-15 09:00:02
这篇文章的制作时间仅在几分钟前,但在功能处理后的页面上显示的结果显示
9小时前
请帮我显示正确的时间

public static function timeago($time){
   $time=strtotime($time);
   $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
   $lengths = array("60","60","24","7","4.35","12","10");
   $now = time();
     $difference = $now - $time;
     $tense= "ago";
     for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
       $difference /= $lengths[$j];
     }
     $difference = round($difference);
     if($difference != 1) {
       $periods[$j].= "s";
     }
   return "$difference $periods[$j] $tense ";
} 
公共静态函数timeago($time){
$time=strottime($time);
$periods=数组(“秒”、“分钟”、“小时”、“日”、“周”、“月”、“年”、“十年”);
$length=数组(“60”、“60”、“24”、“7”、“4.35”、“12”、“10”);
$now=时间();
$difference=$now-$time;
$tense=“ago”;
对于($j=0;$difference>=$length[$j]&&$j
您的问题是没有为时间戳值编写语句, 我的意思是,函数中使用的每个值都被视为时间戳,而不是时间字符串

public static function timeago($time){
    if (!is_numeric($time) || (int)$time != $time)
        $time=strtotime($time);
    $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths = array("60","60","24","7","4.35","12","10");
    $now = time();
    $difference = $now - $time;
    $tense= "ago";
    for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
        $difference /= $lengths[$j];
    }
    $difference = round($difference);
    if($difference != 1) {
        $periods[$j].= "s";
    }
   return "$difference $periods[$j] $tense ";
} 
公共静态函数timeago($time){
如果(!is_numeric($time)| |(int)$time!=$time)
$time=strottime($time);
$periods=数组(“秒”、“分钟”、“小时”、“日”、“周”、“月”、“年”、“十年”);
$length=数组(“60”、“60”、“24”、“7”、“4.35”、“12”、“10”);
$now=时间();
$difference=$now-$time;
$tense=“ago”;
对于($j=0;$difference>=$length[$j]&&$j

顺便说一句,我为我的英语感到抱歉,这不是我的母语。

你自己调试过吗?如果我是你,我会先看一下
$difference
的值。谢谢你帮我把它做好。但它显示的是秒,如
10432秒前
你能更新我以分钟为单位转换吗它作为时间映射和时间字符串对我有效,你能给我你尝试转换的时间戳或时间字符串吗?数据库时间戳
2018-04-15 09:00:02
请帮助我以分钟为单位进行解析好的,我刚刚检查过,你说得对。我用date\u default\u timezone\u set解决了这个问题。这是因为我们在功能中的日期比服务器时间长。请查看此输出屏幕截图它在某处工作不正常它显示秒,现在它做了错误的事情请帮助我