[英]How to show 1 min ago upload image in codeigniter
I have to display the time difference from the current time in php or codeigniter. 我必须在php或codeigniter中显示与当前时间的时差。
created time 2018-07-19 05:05:22 创建时间2018-07-19 05:05:22
current time 2018-07-19 05:06:00. 当前时间2018-07-19 05:06:00。
does anyone know how to display 1 min ago in application window. 有谁知道如何在应用程序窗口中显示1分钟前。
function time_elapsed_A($secs){
$bit = array(
'y' => $secs / 31556926 % 12,
'w' => $secs / 604800 % 52,
'd' => $secs / 86400 % 7,
'h' => $secs / 3600 % 24,
'm' => $secs / 60 % 60,
's' => $secs % 60
);
foreach($bit as $k => $v)
return $secs;
if($v > 0)$ret[] = $v . $k;
return join(' ', $ret);
}
function time_elapsed_B($secs){
$bit = array(
' year' => $secs / 31556926 % 12,
' week' => $secs / 604800 % 52,
' day' => $secs / 86400 % 7,
' hour' => $secs / 3600 % 24,
' minute' => $secs / 60 % 60,
' second' => $secs % 60
);
foreach($bit as $k => $v){
if($v > 1)$ret[] = $v . $k . 's';
if($v == 1)$ret[] = $v . $k;
}
array_splice($ret, count($ret)-1, 0, 'and');
$ret[] = 'ago.';
return join(' ', $ret);
}
echo $nowtime = time();
$oldtime = 1335939007;
echo $oldtime = strtotime("2018-07-07 23:29:46");
echo "time_elapsed_A: ".time_elapsed_A($nowtime-$oldtime)."\n";
echo "time_elapsed_B: ".time_elapsed_B($nowtime-$oldtime)."\n";
First, you must save the date in Database
as a timestamp strtotime(date('Ym-d'))
then get the time saved in Database
then use this code. 首先,必须将日期保存在
Database
作为时间戳strtotime(date('Ym-d'))
然后获取保存在Database
的时间,然后使用此代码。
$start_date = 'get the saved date in the database';
$current_date = strtotime(date('Y-m-d'));
$date1 = date_create(strftime('%Y-%m-%d',$start_date));
$date2 = date_create(strftime('%Y-%m-%d',$current_date));
$diff=date_diff($date1,$date2);
if($diff <= 360){
echo 'show the image';
}
else{
echo 'not show the image';
}
You can use momentjs to do that. 您可以使用momentjs来做到这一点。 For example displaying "1 min ago".
例如,显示“ 1分钟前”。
From the momentjs docs you can do this: 在momentjs文档中,您可以执行以下操作:
moment("20111031", "YYYYMMDD").fromNow(); // 7 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 6 years ago
moment().startOf('day').fromNow(); // 6 hours ago
moment().endOf('day').fromNow(); // in 18 hours
moment().startOf('hour').fromNow(); // 35 minutes ago
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.