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

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));
上一篇:js验证手机号码 ,昵称,密码


下一篇:Service Fabric 与 Ocelot 集成