day incorrect in angular material datepicker

后端 未结 15 1880
挽巷
挽巷 2020-12-08 11:01

When I select a date I see the correct date in the field but, when I save, the datepicker send the day before the date I have selected ( 3 hours offset ) i am using angular

15条回答
  •  感动是毒
    2020-12-08 11:32

    Angular material date picker does not support different time zones at the moment and it gives you an UTC time offset. But to me it is not a problem as i save the output string to my database and when i return it back to user the browser shows the correct date time object. Try this in your console(im in +01 zone) and you will see the selected date:

    new Date('2018-02-08T23:00:00.000Z')
    Fri Feb 09 2018 00:00:00 GMT+0100 (CET)
    

    Another solution is to modify your date object before saving to database which is not the best practice.

    Lastly, If you are using Moment.js in your app you could give the MomentDateAdapter a try and see if it helps you. Just add the MatMomentDateModule to your application as described here.

提交回复
热议问题