• 日期格式之——新增(刚刚,分钟前,小时前,天前)


    日期格式

    代码格式如下:

     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));
  • 相关阅读:
    poj 最长公共子序列 1458 记忆式搜索
    选择排序
    直接 插入排序
    直接插入排序
    洛谷-P3389-高斯消元
    经济中的哪些概念
    uva-622-dp
    UVA-607-DP
    转转---面试题
    Linux事件驱动IO中select vs epoll
  • 原文地址:https://www.cnblogs.com/xuzhudong/p/7153634.html
Copyright © 2020-2023  润新知