欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js 格林威治时间转正常格式并兼容ios

程序员文章站 2022-07-01 20:45:53
调用 ......
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;
        };

调用

var time = '2019-01-10t08:43:00.000+0000';
console.log('time',timechange(time));