• react + ant Upload前端解析excel文件后时间解析为数字转化回日期格式


    方法一:

    (这种方法闰年转化后日期会有问题)

    function formatDate(numb, format) {
            if (numb != undefined) {
     
                let time = new Date((numb - 1) * 24 * 3600000 + 1)
                time.setYear(time.getFullYear() - 70)
                let year = time.getFullYear() + ''
                let month = time.getMonth() + 1 + ''
                let date = time.getDate() + ''
                if (format && format.length === 1) {
                    return year + format + month + format + date
                }
                return year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
            } else {
                return undefined;
            }
        }
    

      

    方法二:

    (正确方法)

    function formatDate(serial, format) {
            var utc_days = Math.floor(serial - 25569);
            var utc_value = utc_days * 86400;
            var date_info = new Date(utc_value * 1000);
            var fractional_day = serial - Math.floor(serial) + 0.0000001;
            var total_seconds = Math.floor(86400 * fractional_day);
            var seconds = total_seconds % 60;
            total_seconds -= seconds;
            var hours = Math.floor(total_seconds / (60 * 60));
            var minutes = Math.floor(total_seconds / 60) % 60;
    
            var daytime = new Date(date_info.getFullYear(), date_info.getMonth(), date_info.getDate(), hours, minutes, seconds);
            var returnDate = date_info.getFullYear();
            returnDate += format + (date_info.getMonth() < 9 ? '0' + (date_info.getMonth() + 1) : (date_info.getMonth() + 1));
            returnDate += format + (date_info.getDate() < 10 ? '0' + date_info.getDate() : date_info.getDate());
            returnDate += " " + (daytime.getHours() < 10 ? '0' + daytime.getHours() : daytime.getHours());
            returnDate += ":" + (daytime.getMinutes() < 10 ? '0' + daytime.getMinutes() : daytime.getMinutes());
            return returnDate;
     } 
    

      

      

  • 相关阅读:
    GET与POST类型接口
    sql查询优化 索引优化
    临时表操作
    sqlserver group by 分组使用详解
    js调用正则表达式
    后台对象转JSON字符串传到前台,前台JSON字符串转对象绑定标签赋值
    string 数组转 int 数组
    巧用XML格式数据传入存储过程转成表数据格式
    存储过程规范写法
    WebApi
  • 原文地址:https://www.cnblogs.com/feng3037/p/14628393.html
Copyright © 2020-2023  润新知