• js 转化为几天前,几小时前,几分钟前...


    转换标准时间为时间戳:

    function getDateTimeStamp(dateStr){
     return Date.parse(dateStr.replace(/-/gi,"/"));
    }

    计算时间差:

     1 function getDateDiff(dateTimeStamp) {
     2             var minute = 1000 * 60;
     3             var hour = minute * 60;
     4             var day = hour * 24;
     5             var halfamonth = day * 15;
     6             var month = day * 30;
     7             var year = day * 365;
     8             var now = new Date().getTime();
     9             var diffValue = now - dateTimeStamp;
    10             if (diffValue < 0) { return; }
    11             var yearC = diffValue / year;
    12             var monthC = diffValue / month;
    13             var weekC = diffValue / (7 * day);
    14             var dayC = diffValue / day;
    15             var hourC = diffValue / hour;
    16             var minC = diffValue / minute;
    17             if (yearC >= 1) {
    18                 result = "" + parseInt(yearC) + "年前";
    19             }
    20             if (monthC >= 1) {
    21                 result = "" + parseInt(monthC) + "月前";
    22             }
    23             else if (weekC >= 1) {
    24                 result = "" + parseInt(weekC) + "周前";
    25             }
    26             else if (dayC >= 1) {
    27                 result = "" + parseInt(dayC) + "天前";
    28             }
    29             else if (hourC >= 1) {
    30                 result = "" + parseInt(hourC) + "小时前";
    31             }
    32             else if (minC >= 1) {
    33                 result = "" + parseInt(minC) + "分钟前";
    34             } else
    35                 result = "刚刚";
    36             return result;
    37         }

    转:http://caibaojian.com/timestamp.html

    js判断某一时间范围:

    参考:  https://zhidao.baidu.com/question/472622390.html

    参考:  https://jingyan.baidu.com/article/9f7e7ec0b98cb46f281554fd.html

  • 相关阅读:
    C#不显示在任务栏
    打开文件,文件夹
    C#文本操作
    C#路径2
    C#当前程序路径获取
    HDU 5155 Harry And Magic Box dp
    POJ 1971 Parallelogram Counting
    CodeForces 479C Exams 贪心
    CodeForces 508E Arthur and Brackets 贪心
    CodeForces 483B 二分答案
  • 原文地址:https://www.cnblogs.com/moy-1313133/p/6937548.html
Copyright © 2020-2023  润新知