Blogger Information
Blog 47
fans 0
comment 2
visits 102677
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类似于微信的聊天时间显示
拾一枝樱花的博客
Original
1963 people have browsed it

function data(data) {
   data = formatDate(data);
   var lc = new Date().setHours(0, 0, 0, 0);// 当前时间的凌晨的时间戳
   var nowlc = new Date(lc);
   var nowTime = nowlc.getTime();
   var nowDay = nowlc.getDay();
   var oneDay = 24 * 60 * 60 * 1000;
   var Monday = nowTime - (nowDay - 1) * oneDay;
   var monday = new Date(Monday);
   var mondaytamp = Number(monday); //当前时间周一凌晨的时间戳
   var date2 = new Date(data);
   var timetamp = Number(new Date(data)); // 转化从时间戳
   var differMin = ((lc - date2) / 1000); // 两个时间相差的秒数
   if (differMin > 0) {
       var min = (differMin / 60).toFixed(0);
       var h = (min / 60).toFixed(0);
       if (h <= 24) {
           data = "昨天"
       } else if (h <= 48) {
           data = "前天"
       } else if (h > 48) {
           var d = timetamp - mondaytamp;
           if (d >= 0) {
               var week = ["日", "一", "二", "三", "四", "五", "六"];
               var index = date2.getDay();
               data = "周" + week[index]
           } else if (d < 0) {
               var year = date2.getFullYear();
               var month = date2.getMonth();
               var day = date2.getDate();
               data = year + "/" + p((month + 1)) + "/" + p(day)
           }
       }
   } else {
       // 当时时间段  时分
       var hour = date2.getHours();
       var minute = date2.getMinutes();
       data = p(hour) + ":" + p(minute)
   }
   return data;
}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post