I use ng-zorro-antd's datepicker in my project,
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
Open F12 first, Then choose one day and click send, You will see the situation in the network parameter.
Thanks a lot.
With the help of moment-timezone.js (front-end or back-end)
get local time zone on client: moment.tz(moment.tz.guess())
define moment date object: moment(yourDate.toISOString())
find the local time zone off set: 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())
format the result 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';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.