[英]ng-zorro datepicker got one day less
I use ng-zorro-antd's datepicker in my project,我在我的项目中使用了 ng-zorro-antd 的 datepicker,
https://ng.ant.design/components/date-picker/en https://ng.ant.design/components/date-picker/en
When I choose the date and time, console will show correct time with timezone like当我选择日期和时间时,控制台将显示正确的时间和时区,例如
Mon Jun 01 2020 05:10:30 GMT+0800 (中國標準時間) {}
But when I submit to backend,the datetime will become但是当我提交到后端时,日期时间会变成
2020-05-31T21:10:30.942Z
It's one day less, How can I resolve this?又少了一天,请问怎么解决?
I make a example like below https://stackblitz.com/edit/angular-acsrm4-gmdget我做了一个像下面的例子https://stackblitz.com/edit/angular-acsrm4-gmdget
Open F12 first, Then choose one day and click send, You will see the situation in the network parameter.先打开F12,然后选择一天点击发送,在网络参数中会看到情况。
Thanks a lot.非常感谢。
With the help of moment-timezone.js (front-end or back-end)借助 moment-timezone.js(前端或后端)
get local time zone on client: moment.tz(moment.tz.guess())
在客户端获取本地时区: moment.tz(moment.tz.guess())
define moment date object: moment(yourDate.toISOString())
定义时刻日期 object: moment(yourDate.toISOString())
find the local time zone off set: moment.tz(moment.tz.guess()).utcOffset()
查找本地时区偏移: moment.tz(moment.tz.guess()).utcOffset()
off set the date object with local time zone off set: moment(yourDate.toISOString()).utcOffset(moment.tz(moment.tz.guess()).utcOffset())
设置日期 object 与本地时区设置: moment(yourDate.toISOString()).utcOffset(moment.tz(moment.tz.guess()).utcOffset())
format the result ISO: format('YYYY-MM-DDTHH:mm:ss.SSS')+'Z'
格式化结果 ISO: format('YYYY-MM-DDTHH:mm:ss.SSS')+'Z'
Single Line: yourDate = moment(yourDate.toISOString()).utcOffset(moment.tz(moment.tz.guess()).utcOffset()).format('YYYY-MM-DDTHH:mm:ss.SSS')+'Z';
单行: yourDate = moment(yourDate.toISOString()).utcOffset(moment.tz(moment.tz.guess()).utcOffset()).format('YYYY-MM-DDTHH:mm:ss.SSS')+'Z';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.