时间:2021-05-26
效果图:
代码如下:
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <ul> <li class="one-comment"> <a class="c-user-photo" href=""><img src=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" img/user_photo.png" alt="" /></a> <div class="comment-info"> <h3 class="userinfo clearfix"><a href="" class=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" name">大黄蜂</a><span class="fl-right tags"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-reply">回复</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-support">点赞</a></span></h3> <p class="time">2017-04-25 09:26:02</p> <p class="content">的确很漂亮啊,拍照技术越来越好了</p> </div> </li><li class="one-comment"> <a class="c-user-photo" href=""><img src=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" img/user_photo.png" alt="" /></a> <div class="comment-info"> <h3 class="userinfo clearfix"><a href="" class=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" name">大黄蜂</a><span class="fl-right tags"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-reply">回复</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-support">点赞</a></span></h3> <p class="time">2017-04-22 09:26:02</p> <p class="content">的确很漂亮啊,拍照技术越来越好了</p> </div> </li> </li><li class="one-comment"> <a class="c-user-photo" href=""><img src=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" img/user_photo.png" alt="" /></a> <div class="comment-info"> <h3 class="userinfo clearfix"><a href="" class=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" name">大黄蜂</a><span class="fl-right tags"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-reply">回复</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-support">点赞</a></span></h3> <p class="time">2017-04-26 17:50:02</p> <p class="content">的确很漂亮啊,拍照技术越来越好了</p> </div> </li> </li><li class="one-comment"> <a class="c-user-photo" href=""><img src=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" img/user_photo.png" alt="" /></a> <div class="comment-info"> <h3 class="userinfo clearfix"><a href="" class=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" name">大黄蜂</a><span class="fl-right tags"><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-reply">回复</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-support">点赞</a></span></h3> <p class="time">2017-04-26 09:26:02</p> <p class="content">的确很漂亮啊,拍照技术越来越好了</p> </div> </li> </ul> <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> //开发中我们需要计算一条动态的发布时间,一般我们得到的是一条日期字符串,我们需要计算当前时间和动态的发布时间,计算它们的差值来判断发布在什么时候 //Date.parse() 解析一个日期时间字符串,并返回1970/1/1 午夜距离该日期时间的毫秒数 //var nDays = Math.abs(parseInt((time2 - time1)/1000/3600/24)); // 获取当前时间戳(以s为单位) function setTime(time,timeSelector){ var currentTime = Date.parse(new Date()); var dateTime = time;//后台传递来的时间 var ts = timeSelector;//选择器 var d_day = Date.parse(new Date(dateTime)); var day = Math.abs(parseInt((d_day - currentTime)/1000/3600/24));//计算日期 var hour = Math.abs(parseInt((d_day - currentTime)/1000/3600));//计算小时 var minutes = Math.abs(parseInt((d_day - currentTime)/1000/60));//计算分钟 var seconds = Math.abs(parseInt((d_day - currentTime)/1000));//计算秒 console.log(day); if(day >= 2){ ts.text(parseInt(day)+"天前").toString(); }else if(day > 0 && day < 2){ ts.text("昨天").toString(); }else if(hour > 0 && hour < 24){ ts.text(parseInt(hour)+"小时前").toString(); }else if(minutes > 0 && minutes < 60){ ts.text(parseInt(minutes)+"分钟前").toString(); }else if(seconds > 0 && seconds < 60){ ts.text(parseInt(seconds)+"秒前").toString(); } } //列表里面调用方法,传递两个参数 数据库时间和选择器 $(".one-comment").each(function(){ var t_time = $(this).find(".time").text(); var timeSelector = $(this).find(".time"); setTime(t_time,timeSelector); }) </script> </body></html>以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
这篇文章主要介绍了Oracle通过时间(分钟)计算有几天几小时几分钟的方法,涉及Oracle时间操作的技巧,需要的朋友可以参考下本文实例讲述了Oracle通过时
最近在做项目的时候,需要把后台返回的时间转换成几秒前、几分钟前、几小时前、几天前等的格式;后台返回的时间格式为:2015-07-3009:36:10,需要根据当
在项目中时间一律显示为2014-10-2010:22显得很呆板。在微博、QQ空间等网站通常会显示为几秒前,几分钟前,几小时前等容易阅读的时间,我们称之为友好的时
在项目中时间一律显示为2014-10-2010:22显得很呆板。在微博、QQ空间等网站通常会显示为几秒前,几分钟前,几小时前等容易阅读的时间,我们称之为友好的时
这里汇总了js实现时间显示几天前、几小时前或者几分钟前的常见方法。分享给大家供大家参考。具体如下:方法一:个人做法是保存时间戳,然后在前端用jq插件做转换,比如