• Javascript 日期转换 几天前


    时间函数

    function formatDt(date) {
    // ReSharper disable once IdentifierTypo
        var yare = date.getYear() + 1900;
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        var minutes = date.getMinutes();
        var second = date.getSeconds();
    
        month = month.toString().padStart(2,'0');
        day = day.toString().padStart(2,'0');
        hour = hour.toString().padStart(2,'0');
        minutes = minutes.toString().padStart(2,'0');
        second = second.toString().padStart(2,'0');
    
        return `${yare}-${month}-${day} ${hour}:${minutes}:${second}`;
    }

    将几天前  转换为当前时间

    var dtReg = /d{4}年d{2}月d{2}日 d{2}:d{2}/
    var minReg = /d+(?=分钟前)/
    var houReg = /d+(?=小时前)/
    var dayReg = /d+(?=天前)/
    
    
    function dtToString(date) {
        var yare = date.getYear() + 1900
        var month = date.getMonth() + 1
        var day = date.getDate()
        var hour = date.getHours()
        var minutes = date.getMinutes()
        var second = date.getSeconds()
        return `${yare}-${month}-${day} ${hour}:${minutes}:${second}`
    }
    
    if (dtReg.test(input)) {
        input = input.replace('年', '-')
        input = input.replace('月', '-')
        input = input.replace('日', '')
        input = input+':00'
    } else if (minReg.test(input)) {
        var now = new Date()
        var count = Number(minReg.exec(input))
        var dt = now - count * 60 * 1000
        input = formatDt(new Date(dt))
    } else if (houReg.test(input)) {
        var now = new Date()
        var count = Number(houReg.exec(input))
        var dt = now - count * 60  * 60 * 1000
        input = formatDt(new Date(dt))
    }
     else if (dayReg.test(input)) {
        var now = new Date()
        var count = Number(dayReg.exec(input))
        var dt = now - count * 60  * 60 * 24 * 1000
        input = formatDt(new Date(dt))
    }
  • 相关阅读:
    SQL注入
    SQL注入
    CSRF
    Docker官方Tomcat映像修改Server.xml
    github+jenkins+maven+docker自动化构建部署
    Docker下的Jenkins
    拿来即用学PYTHON:序
    Python-字典
    Python-列表与元组
    程序员英语轻松学1
  • 原文地址:https://www.cnblogs.com/mailaidedt/p/12264288.html
Copyright © 2020-2023  润新知