zoukankan      html  css  js  c++  java
  • 日期格式之——新增(刚刚,分钟前,小时前,天前)

    日期格式

    代码格式如下:

     1 function dateStr(date){
     2     //获取js 时间戳
     3     var date = date.getTime();
     4     var time=new Date().getTime();
     5     //去掉 js 时间戳后三位,与php 时间戳保持一致
     6     time=parseInt((time-date)/1000);
     7 
     8     //存储转换值 
     9     var s;
    10     if(time<60*10){//十分钟内
    11         return '刚刚';
    12     }else if((time<60*60)&&(time>=60*10)){
    13         //超过十分钟少于1小时
    14         s = Math.floor(time/60);
    15         return  s+"分钟前";
    16     }else if((time<60*60*24)&&(time>=60*60)){ 
    17         //超过1小时少于24小时
    18         s = Math.floor(time/60/60);
    19         return  s+"小时前";
    20     }else if((time<60*60*24*3)&&(time>=60*60*24)){ 
    21         //超过1天少于3天内
    22         s = Math.floor(time/60/60/24);
    23         return s+"天前";
    24     }else{ 
    25         //超过3天
    26         var date= new Date(date);
    27         return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":" +date.getMinutes()+":"+ date.getSeconds();
    28     }
    29 }
    30   var t = new Date("2017-7-7 8:20:20");
    31   console.log(dateStr(t));
  • 相关阅读:
    junit4的初级用法
    junit3和junit4的区别总结
    工作一年多了,我的技术博客终于开通了
    VC++ 运行库官方安装包
    文本编辑器通用快捷键
    gcc命令介绍
    MinGW安装与配置
    windows常见快捷键
    Notepad++配置C/C++
    Notepad++快捷键
  • 原文地址:https://www.cnblogs.com/xuzhudong/p/7153634.html
Copyright © 2011-2022 走看看