components icon indicating copy to clipboard operation
components copied to clipboard

Can't save local date with datepicker.

Open aspramsh opened this issue 7 years ago • 5 comments

aspramsh avatar Feb 06 '19 19:02 aspramsh

I am using material's datepicker. When I select date, everything is ok, but after passing it to the server I get the previous day, that is 4 hours before, my time zone is UTC + 4. How can I make it not to subtract 4 hours?

aspramsh avatar Feb 06 '19 19:02 aspramsh

Try using string instead of datetime in backend

mehmetkarpuz avatar Feb 11 '19 07:02 mehmetkarpuz

I have the same problem and I found a solution from here: https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings

I added the following code to the module providers and then it works.

providers: [ { provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } } ]

zhiyue-yi avatar Feb 14 '19 07:02 zhiyue-yi

The datepicker returns Date instances (or Moment instances if using the moment date adapter). It's up to you to decide how these are stringified and stored in your backend.

mmalerba avatar May 27 '20 19:05 mmalerba

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.