Hello,
I'm trying to have a datepicker start with no value and when the user fills it I would like the UTC date to match the datepicker's date. When I have line 17 enabled this works as I would like. However when commenting line 17 and enabling line 18, the dateModel suddenly gives a date that's one day before the datepicker's.
How can I circumvent this?
Da7opd (forked) - StackBlitz
I'm trying to have a datepicker start with no value and when the user fills it I would like the UTC date to match the datepicker's date. When I have line 17 enabled this works as I would like. However when commenting line 17 and enabling line 18, the dateModel suddenly gives a date that's one day before the datepicker's.
How can I circumvent this?
Da7opd (forked) - StackBlitz
Hello, Vincent.
Thank you for the shared details about your scenario. If I am correctly understanding, you want to work with UTC Date value and not with the Date value of your current time zone.
Before I continue furhter, I want to share why you get the shared behavior. When you select a date in the DatePicker(let's say 29 Jun 2023 GMT +3, for example), the DatePicker's value would be 29 Jun 2023 00:00:00 GMT+3. The time in yellow is actually 28 Jun 2023 21:00:00 UTC. The previous is why the date is being changed in the solution you shared with us. I hope I described it clearly.
Here is a StackBlitz example in which the localeDate object is set according to your requirements.
Please check the above example and let me know if it demonstrates what you need to implement in your application.