js时区时间转换格式:h5内转换含有T字母的8小时时区时间格式 2019-11-23T00:00:00.000+0000

var date = "2019-11-23T00:00:00.000+0000";
    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]);

    function formatDateTime (date) {
        let time = new Date(Date.parse(date));
        time.setTime(time.setHours(time.getHours() + 8));

        // alert(time);
        // if (!isNaN(time)) {
        //     return new Date(Date.parse(date.replace(/-/g, "/")));
        // } else {
        let Y = time.getFullYear() + '-';
        let M = this.addZero(time.getMonth() + 1) + '-';
        let D = this.addZero(time.getDate()) + ' ';
        let h = this.addZero(time.getHours()) + ':';
        let m = this.addZero(time.getMinutes()) + ':';
        let s = this.addZero(time.getSeconds());
        return Y + M + D + h + m + s;
        // }
    };
    // 数字补0操作
    function addZero(num) {
        return num < 10 ? '0' + num : num;
    };

    console.log(this.formatDateTime(dd));

    // const date = new Date("2019-11-23T00:00:00.000+0000");
    // console.log("date:",date);
    console.log("Date:",new Date());

 

你可能感兴趣的:(前端)