JS 不同时间格式转换(ISO时间&时间戳转北京时间)

 //格林尼治2019-03-19T16:00:00.000Z  ==>>  2019-03-20 00:00:00   与北京时间8小时时差
            //格林尼治2019-03-19T16:00:00.000Z  ==>>  2019-03-20 00:00:00 
	       // //时间戳1553547600000  转 //  2019-03-25T21:00:00.000Z
            function formDate(dateForm) {
                if (dateForm === "") {  //解决deteForm为空传1970-01-01 00:00:00
                    return "";
                }else{
                    var dateee = new Date(dateForm ).toJSON();
                    var date = new Date(+new Date(dateee)+ 8 * 3600 * 1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
                    return date;
                }
            }
            console.log(formDate("2019-03-19T16:00:00.000Z"))//2019-03-20 00:00:00
            console.log(formDate(1553547600000))             //2019-03-26 05:00:00
            console.log(formatDateT(1553547600000))          //2019-03-25T21:00:00.000Z

             //时间戳1553547600000  转 //  2019-03-25T21:00:00.000Z
            function formatDateT(dataTime){
                // var timestamp3 = 1551686227000; 
                var timestamp = dataTime;
                var newDate = new Date(dataTime ); 
                // var newDate = new Date(dataTime + 8 * 3600 * 1000 );               

                newDate.getTime(timestamp * 1000);                
                // console.log(newDate.toDateString());//Mon Mar 11 2019                
                // console.log(newDate.toGMTString()); //Mon, 11 Mar 2019 06:55:07 GMT                
                // console.log(newDate.toISOString()); //2019-03-11T06:55:07.622Z
                return newDate.toISOString()
            }

 

 

 

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值