✸ ✸ ✸
问题:
使用element-ui DateTimePicker组件 直接将值传给后台发现选择的时间比正常时间慢8小时。

前台console.log显示:
[Thu Mar 07 2019 12:00:00 GMT+0800 (中国标准时间), Mon Apr 15 2019 00:00:00 GMT+0800 (中国标准时间), __ob__: Observer]
与所选时间一致,但是到了后台却慢了8小时:
[u'2019-03-07T04:00:00.000Z', u'2019-04-14T16:00:00.000Z']
解决方法:
前台:
let start_time = ''
let end_time = ''
if (this.times.length === 2) {
start_time = this.times[0].getFullYear() + '-' + (this.times[0].getMonth() + 1) + '-' + this.times[0].getDate() + ' ' + this.times[0].getHours() + ':' + this.times[0].getMinutes() + ':' + this.times[0].getSeconds();
end_time = this.times[1].getFullYear() + '-' + (this.times[1].getMonth() + 1) + '-' + this.times[1].getDate() + ' ' + this.times[1].getHours() + ':' + this.times[1].getMinutes() + ':' + this.times[1].getSeconds();
}
后台:
if start_time!='':
start_time=datetime.strftime(datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
end_time=datetime.strftime(datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
后台输出:
2019-03-07 12:00:00 2019-04-15 00:00:00
不但 时间对了,顺便还进行了所需格式的格式化
✸ ✸ ✸
📜 版权声明
本文作者:王梓 | 原文链接:https://www.bthlt.com/note/9269850-CssJsHtmlDateTimePicker时间慢8小时
出处:葫芦的运维日志 | 转载请注明出处并保留原文链接


📜 留言板
留言提交后需管理员审核通过才会显示