Why is my date getting parsed differently when starting out with no default value for DatePicker?

0 Answers 60 Views
DatePicker
Vincent
Top achievements
Rank 3
Iron
Iron
Iron
Vincent asked on 27 Jun 2023, 02:14 PM
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
Petar
Telerik team
commented on 29 Jun 2023, 02:15 PM

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. 

No answers yet. Maybe you can help?

Tags
DatePicker
Asked by
Vincent
Top achievements
Rank 3
Iron
Iron
Iron
Share this question
or