【问题标题】:How to convert current timestamp in timeago in codeigneiter如何在codeigniter中转换当前时间戳
【发布时间】:2021-07-28 21:21:44
【问题描述】:

我想在 codeigneiter 3 中显示当前日期时间的时间前格式

我想将此代码转换为几小时前

【问题讨论】:

  • 感谢您告知我们。祝你好运!

标签: php jquery date time timeago


【解决方案1】:
Hello please follow this

echo time_elapsed_string('2013-05-01 00:22:35');
echo time_elapsed_string('@1367367755'); # timestamp input
echo time_elapsed_string('2013-05-01 00:22:35', true);

function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);

$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;

$string = array(
   
    'y' => 'year',
    'm' => 'month',
    'w' => 'week',
    'd' => 'day',
    'h' => 'hour',
    'i' => 'minute',
    's' => 'second',
   
);
foreach ($string as $k => &$v) {
    if ($diff->$k) {
        $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
    } else {
        unset($string[$k]);
    }
}

if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}

【讨论】:

  • 谢谢先生,但我已经通过时间跨度做到了这一点
  • 我给你 3 种方式 echo time_elapsed_string('2013-05-01 00:22:35'); echo time_elapsed_string('@1367367755'); # 时间戳输入 echo time_elapsed_string('2013-05-01 00:22:35', true);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-29
  • 2017-06-11
  • 1970-01-01
  • 2013-09-26
  • 2020-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多