900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > jQuery 将本地时间转换成 UTC 时间 计算时差 将UTC时间转换成 本地 时间

jQuery 将本地时间转换成 UTC 时间 计算时差 将UTC时间转换成 本地 时间

时间:2020-11-25 01:30:20

相关推荐

jQuery 将本地时间转换成 UTC 时间 计算时差 将UTC时间转换成 本地 时间

//使用方式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;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。