本文介绍了代码间隔时间函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我现在搜索洞web,发现了很多,但我只是不知道如何使它工作,所以现在我要求这里帮助
Hello i have now search the hole web and found a lot but i just dont know how to make it to work so now im asking here for help
我想为了做到这一点,一个人创建一个评论,它应该说创建1秒前,然后1分钟和1小时,像这样:)
i want to do so then a person create a comment it should said "created 1 sec. ago" and then 1 min and 1 hour and like that :)
可以一些帮助
感谢
推荐答案
你要什么。当你使用函数set $ deep参数为1时。
I think this is exactly what you want. When you using the function set $deep parameter to 1.
function timespan($seconds = 1, $time = '', $deep = NULL)
{
$CI = & get_instance();
$CI->lang->load('date');
$current_deep = 0;
if (!is_numeric($seconds))
{
$seconds = 1;
}
if (!is_numeric($time))
{
$time = time();
}
if ($time <= $seconds)
{
$seconds = 1;
}
else
{
$seconds = $time - $seconds;
}
$str = '';
$years = floor($seconds / 31536000);
if ($years > 0)
{
$str .= $years . ' ' . $CI->lang->line((($years > 1) ? 'date_years' : 'date_year')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $years * 31536000;
$months = floor($seconds / 2628000);
if ($years > 0 OR $months > 0)
{
if ($months > 0)
{
$str .= $months . ' ' . $CI->lang->line((($months > 1) ? 'date_months' : 'date_month')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $months * 2628000;
}
$weeks = floor($seconds / 604800);
if ($years > 0 OR $months > 0 OR $weeks > 0)
{
if ($weeks > 0)
{
$str .= $weeks . ' ' . $CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $weeks * 604800;
}
$days = floor($seconds / 86400);
if ($months > 0 OR $weeks > 0 OR $days > 0)
{
if ($days > 0)
{
$str .= $days . ' ' . $CI->lang->line((($days > 1) ? 'date_days' : 'date_day')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $days * 86400;
}
$hours = floor($seconds / 3600);
if ($days > 0 OR $hours > 0)
{
if ($hours > 0)
{
$str .= $hours . ' ' . $CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $hours * 3600;
}
$minutes = floor($seconds / 60);
if ($days > 0 OR $hours > 0 OR $minutes > 0)
{
if ($minutes > 0)
{
$str .= $minutes . ' ' . $CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')) . ', ';
if (++$current_deep == $deep)
return substr(trim($str), 0, -1);
}
$seconds -= $minutes * 60;
}
if ($str == '')
{
$str .= $seconds . ' ' . $CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')) . ', ';
}
return substr(trim($str), 0, -1);
}
这篇关于代码间隔时间函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!