-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DatePicker timezone problem #3609
Comments
+1 |
Help us!!!! |
Same problem! |
+1 |
The problem shows up when the Date is converted to JSON. I solved the problem overriding Date.prototype.toJSON method returning Date in string format yyyy-MM-dd'T'hh:mm:ss. This work for me. |
Same Problem Here. Can you post some example code? How many years this issue exists?? Isn't this a bit unacceptable?? |
This is my code `Date.prototype.toJSON = function(){ Server side I accept date in "yyyy-MM-dd'T'HH:mm:ss" format ` |
Would #3440 solve this issue? |
This is actually expected date behaviour in js. |
@valorkin where would you call Edit: fwiw, we're working around this by just making sure that the date before getting shown in the datepicker doesn't have any timezone info on it (so that Date renders it in the client's timezone) and then chopping off the time information before sending it back to the server. |
why is this closed... still a problem and no solution!? |
I had the same problem.
U need to include moment.js and moment-timezon.js |
Was that workaround then found ? |
Is there workaround for timezone issue? I want to have datepicker for UTC Date selection. |
https://medium.com/self-learning/ngx-datepicker-utc-datepicker-design-77e33789e9d7 I have tried a UTC Datepicker which is a wrapper to original datepicker. The wrapper try to convert the input with a timezone offset procession.
Remark for this solution |
Really?!? We need to a special custom function to handle such a simple problem!? This is so stupid! |
@imben1109 @Hojekunle @waldof123 @viktor-mezhenskyi @roscoedeemarutam Please, try this version |
@Domainv I took a look on ngx-bootstrap-ci@d94457108f5fd2527b7cab501e1cc0271a087a08. It should be my expected result. I want to try on this version by npm install ngx-bootstrap-ci@d94457108f5fd2527b7cab501e1cc0271a087a08
I have another issue for custom timezone which I want to select a timezone which is different from the timezone browser timezone offset. e.g. Browser Timezone: +7 The below is my workaround solution. Could you take a look?
|
@imben1109 |
@isalox Provide more info, please. |
same problem, datepicker return one day behind |
take a look here: just click Set Date and you will see in control date 1 day back |
Thanks, guys, I'll fix it as soon as possible. |
@isalox @Domainv Therefore, i think UTC Time should be used. https://stackblitz.com/edit/angular-mb7szh
instead of
And that is why i need a wrapper for my workaround solution. As my situation, i need a datepicker for UTC+0 situation (by my workaround solution). |
@imben1109 If I understand right, for you datepicker works correctly now? |
it is just for example. Actually my problem is when I am getting data from Rest API. In data base, i store only dates without time. That data is send to UI and deserializes and when I want to edit I am getting dates one day back. |
I had the same issue, for some reasons, bsDatepicker always picked the day before the date you choose. Here is a solution I found which uses datepipe from angular/common. let dateFromBsdatepicker:Date = reactiveForm['formControlName']; |
@isalox you could try my workaround solution that i post before. a utc date wrapper for ngx-bootstrap for version before 5.2.0 |
Released ngx-bootstrap@5.3.2 behavior was back as in 5.1.2 version Needs more info and time to find the correct solution for timezone issue |
after an afternoon and an evening plenty of frustration, I switched to a simple input control type=date and the date is saved without time, what I needed for my case |
I don't need any workarounds. It should work properly without any hacks. It is basic functionality for datepicker. If it can't render date correctly why do anyone need it. Right now it is useless. |
Any idea when a fix will be available? |
I came to check this issue after 1 year and mods still need info about the issue. Maybe in year 3020 they will find root cause and in year 4020 it is expected to be solved. |
@Omi231 very funny joke, thanks |
its 2 years from first post and this issues is not fix ? |
@Domainv Maybe you should consider to extend date picker config. It will be great if anyone could decide how output should look like. If I got it right - only problem is, that you are sending date object to onChange function here. Something like this with default value should solve this problem.
with default value
When configured like @imben1109 do that
It should return correct date and also could help to return to those who wants same output as dateInput format. This will also help because it did not drop information about timezone -
But it will create breaking change... So I dont think it is solution. |
funny parts of being a developer :) |
I've exactly the same problem here. Any idea or fixes? |
@dinhanhthi I made wrapper around this component and use it instead. If you do not need all original Inputs and Outputs it should be easy and small component.
utc-datepicker.component.ts
utc-datepicker.component.html
Usage example:
|
@blazekv Thanks for a very detailed answer. For a moment, I've found a simpler solution rather than using your suggestion. It suits only for my case, not the problem in this topic. I've noted your way and may use in the future. Thanks. |
@blazekv Great solution you saved my day, just add the .html of the component Hope the team fixes this issue or at least provides a good reason why it is there. Best regards |
@zakarea-Tfaili I have updated previous post and added template. |
@blazekv Great solution you saved my day too!!!! Great solution |
A quick workaround in my case is to avoid moment in formatting the date before using it in this datepicker.... |
this is solved the issue here is example: https://stackblitz.com/edit/angular-usdq2z |
I had used Formate "DD/MM/YYYY". I was getting the issue, when update the date then it was updating correct date up to three time and when I was trying for forth time, Date was changed by datepicker hence it was updating the wrong date to database. I Got the solution and It works properly but It is the proper way or not I don't know Scenario : 1.) First Time open DatePicker and update the same date. 2.) Second Time open DatePicker and update the same date. 3.) Third Time open DatePicker and update the same date. 4.) Forth Time when I open the DakePicker It changed the date. Solution :
So I made change while fetching the record |
[bsConfig]="{ dateInputFormat: 'YYYY-MM-DD' }"
when this format is used, i may expect the same entry come back regardless of client. because we are selecting a date not datetime. But its considering it as datetime and puts timezone info to it.
So, for example, 2018-01-30 00:00:00 becomes 2018-01-29 if your timezone is +
There is no config option to set timezone or any thing that allows to retreive the input directly.
If there is a way, i am not aware but per the source code, i dont see any option that lets this.
The text was updated successfully, but these errors were encountered: