zoukankan      html  css  js  c++  java
  • js格林威治时间转换成正常时间

    //时间转换
        changeTime(time) {
        //time 为 '2020-06-15T07:23:17.000+0000' let time2
    = this.myTime(time); let time3 = this.formatDateTime(time2); return time3; //time3 为转换后的时间 2020-06-15 15:23:14 }, myTime(date) { var arr = date.split("T"); var d = arr[0]; var darr = d.split("-"); var t = arr[1]; var tarr = t.split(".000"); var marr = tarr[0].split(":"); var dd = parseInt(darr[0]) + "/" + parseInt(darr[1]) + "/" + parseInt(darr[2]) + " " + parseInt(marr[0]) + ":" + parseInt(marr[1]) + ":" + parseInt(marr[2]); return dd; }, addZero(num) { return num < 10 ? "0" + num : num; }, formatDateTime(date) { var time = new Date(Date.parse(date)); time.setTime(time.setHours(time.getHours() + 8)); // time.setTime(time.setHours(time.getHours())); var Y = time.getFullYear() + "-"; var M = this.addZero(time.getMonth() + 1) + "-"; var D = this.addZero(time.getDate()) + " "; var h = this.addZero(time.getHours()) + ":"; var m = this.addZero(time.getMinutes()) + ":"; var s = this.addZero(time.getSeconds()); return Y + M + D + h + m + s; }

    方法2

    function timeChange(time) {
                var date = time.substr(0, 10); //年月日
                var hours = time.substring(11, 13);
                var minutes = time.substring(14, 16);
                var seconds = time.substring(17, 19);
                var timeFlag = date + ' ' + hours + ':' + minutes + ':' + seconds;
                timeFlag = timeFlag.replace(/-/g, "/");
                timeFlag = new Date(timeFlag);
                timeFlag = new Date(timeFlag.getTime() + 8 * 3600 * 1000);
                timeFlag = timeFlag.getFullYear() + '-' + ((timeFlag.getMonth() + 1) < 10 ? "0" + (timeFlag.getMonth() + 1) : (timeFlag.getMonth() + 1)) + '-' + (timeFlag.getDate() < 10 ? "0" + timeFlag.getDate() : timeFlag.getDate()) + ' ' + timeFlag.getHours() + ':' + timeFlag.getMinutes() + ':' + (timeFlag.getSeconds() < 10 ? "0" + timeFlag.getSeconds() : timeFlag.getSeconds());
                return timeFlag;
            };

    调用 

    timeChange(2020-06-15T07:23:17.000+0000) //2020-06-15 15:23:14
  • 相关阅读:
    C语言之基本算法24—黄金切割法求方程近似根
    windows下PHP不能开启pgsql扩展的解决方法
    Linux 文件基本属性
    Android倒计时功能的实现
    hdu2444The Accomodation of Students (最大匹配+推断是否为二分图)
    Asp.net core使用IIS在windows上进行托管
    [Asp.net]web.config customErrors 如何设置?
    [Asp.net mvc]Html.ValidationSummary(bool)
    [C#基础]说说lock到底锁谁?(补充与修改)
    [web.config]如何灵活使用配置文件
  • 原文地址:https://www.cnblogs.com/Byme/p/13151313.html
Copyright © 2011-2022 走看看