如何根据当前用户信息时间显示时间状态的PHP代码

2022-11-12 0 53

如何根据当前用户信息时间显示时间状态的PHP代码?

 

以下代码为项目开发片段,实现方法仅供参考。

$created_at = !empty($v->created_at) ? $v->created_at : $v->created_at_as;

$time_differents = time() – strtotime($created_at);

$time_differents = round($time_differents/3600, 3);

//返回当前时间状态

switch ($time_differents) {

case $time_differents <= 0.033:

$data[$k]->visit_time = ‘刚刚’;

break;

 

case $time_differents <= 0.033 && $time_differents < 1:

$data[$k]->visit_time = round($time_differents*60, 0).’分钟前’;

break;

 

case $time_differents <= 1 && $time_differents < 24:

$data[$k]->visit_time = round($time_differents).’小时前’;

break;

 

case $time_differents <= 24 && $time_differents < 48:

$data[$k]->visit_time = ‘昨天’;

break;

 

case $time_differents <= 48 && $time_differents < 72:

$data[$k]->visit_time = ‘2天前’;

break;

 

case $time_differents <= 72 && $time_differents < 96:

$data[$k]->visit_time = ‘3天前’;

break;

 

case $time_differents <= 96 && $time_differents < 120:

$data[$k]->visit_time = ‘4天前’;

break;

 

case $time_differents <= 120 && $time_differents < 144:

$data[$k]->visit_time = ‘5天前’;

break;

 

case $time_differents <= 144 && $time_differents < 168:

$data[$k]->visit_time = ‘6天前’;

break;

 

case $time_differents <= 168 && $time_differents < 336:

$data[$k]->visit_time = ‘1周前’;

break;

 

default:

# code…

break;

}

1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!cheeksyu@vip.qq.com
2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理!
3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负!
4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有积分奖励和额外收入!
5.严禁将资源用于任何违法犯罪行为,不得违反国家法律,否则责任自负,一切法律责任与本站无关

发表评论
暂无评论