-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Datepicker shows one day behind when using yyyy-MM-dd format #2628
Comments
+1, can confirm. |
I have the same issue, any solutions? |
This is probably a time zone issue, try displaying model.toISOString() to see. |
@awb You are right 👍 . I could solve this adding timezone with getTimezoneOffset() :) |
So is this fixable on my end or is this a bug within the directive? I'm passing a date like "2014-09-10" and the datepicker dropdown is displaying 2014-09-09 but the input is correct. |
I fixed it simply by converting all date strings (my backend returns ISO dates like 2014-09-10) into date objects in my controller. |
This is how I fixed it. I added my timezone var d = new Date('yourDate'); 'd' should be the correct date |
Please put this in the docs - I just realized this as well (too late). For yyyy-MM-dd it does not make sense, since the user is not entering a time value, so time is always T00:00:00 (+/- the gmt offset when converted to string) |
This should now be addressed in 0.14.3. There are still some timezone issues, i.e. the weakness in not being able to configure it, but one can set the timezone used by the datepicker via setting an initial model date value with the appropriate timezone. |
This is still not fixed.
This outputs:
Today is the 7th! |
I guess, I am experiencing the same issue right now, version 1.3.3 |
I'm experiencing this same issue, and I'm not even concerned with the time of day. I just want to be able to choose a day. Picker keeps picking the day before. Not a good outcome for me. |
I ran into this yesterday and found the solution is to set the timezone option to utc and the date is no longer off by one. The syntax for doing that is here: #4837 (comment) |
Thanks Elijah. But that did not resolve the issue for me. I really wish they would fix this bug, rather than just close the many Issues that people raise which reference it. |
If you'd like to hardcode a timezone, you could do what I did. As @charger513 mentioned, you can set the minutes along with the timezone offset -- but instead of determining your current timezone automatically, you could substitute the timezone offset with the amount of minutes - in my case, my local timezone was returning
I was then finally getting the output I wanted - as my PHP backend counterpart was aligned to the UTC+08 timezone. Find your timezone minutes offset here: https://forbrains.co.uk/international_tools/earth_timezones |
I have found a way. convert that date to string first.
Now Pass SelectDate to your controller. |
Can't believe this is still a bug.. |
I solved this issue by giving the Date field in Backend as Edm.DateTimeOffset (this will be a Timestamp field in ABAP) & converting the timestamp field to Date & Time by using function module - IB_CONVERT_FROM_TIMESTAMP. |
if you are using moment, you can user the 'utc date' |
This works for me var DatePickerDate ='Thu Aug 09 2018 00:00:00 GMT+0100 (British Summer Time)'; var myDate = new Date(DatePickerDate).toISOString(); so myDate is now 2018-08-08T23:00:00.000Z |
If you are using Java-Hibernate, use the Date as type String in your Model(POJO) when reaching the controller to collect ModelAttribute. This issue occurs If you use it as type DateTime in your Java. |
+1 |
when will this be fixed I still got the same problem using the latest version of angular and material. but I am not using yyyy-mm-dd I am just using standard material date picker. |
The text was updated successfully, but these errors were encountered: