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));
  • 相关阅读:
    django-搭建BBS关键点总结
    关于django中input标签中file类型以及开路由
    Bzoj1115 石子游戏Kam
    HDU1907 John
    HDU2509 Be the Winner
    洛谷P1082 同余方程
    POJ1065 Area
    Vijos1889 天真的因数分解
    Bzoj2440 完全平方数
    Bzoj2705 Longge的问题
  • 原文地址:https://www.cnblogs.com/xuzhudong/p/7153634.html
Copyright © 2011-2022 走看看