//使用方式let date = 'YYYY-MM-DD'; //你的时间格式(你的时间)//调用FormatUtcDate(new Date( date + ' 00:00:00 '))FormatLocaDate(new Date( date + ' UTC '))
//将本地时间转换成UTC时间(减去计算时差)function FormatUtcDate(obj){var str = '';str += obj.getUTCFullYear() + '-';if ((obj.getUTCMonth() + 1) < 10) {str += '0' + (obj.getUTCMonth() + 1) + '-';}else{str += (obj.getUTCMonth() + 1) + '-';}if (obj.getUTCDate() < 10) {str += '0' + obj.getUTCDate();} else {str += obj.getUTCDate();}return str +' '+ obj.getUTCHours() +':'+ obj.getUTCMinutes() +':'+ obj.getUTCSeconds();}//将UTC 时间转换成本地时间(添加计算时差)function FormatLocaDate(obj){var str = '';str += obj.getFullYear() + '-';if ((obj.getMonth() + 1) < 10) {str += '0' + (obj.getMonth() + 1) + '-';}else{str += (obj.getMonth() + 1) + '-';}if (obj.getDate() < 10) {str += '0' + obj.getDate();} else {str += obj.getDate();}return str;}