jsタイムゾーン時間変換フォーマット:h 5内変換T字母を含む8時間タイムゾーン時間フォーマット2019-11-23 T 00:00:00:00+0000

1457 ワード

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());