cssjshtml DateTimePicker时间慢8小时

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 3804

2019/03/22 19:55


问题:

使用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

不但 时间对了,顺便还进行了所需格式的格式化

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1