Angular: the backend saves the wrong date

Updated: 2022-01-05

In the database is saved a date different from the date of the datepicker

This error is frequent when the date is passed to the backend via REST api.

When we are using a timezone defined time this one is converted by the REST service and the data saved in the backend differs 1 day from the date used in the frontend.

A simple approach to remove the issue is to convert the date in the frontend, e.g. using moment.js:

dateUsedInTheCode.format('yyyy-MM-DD') this removes the timezone and it avoids format errors.


You could be interested in

Angular common error messages

Angular message errors ... again this one ... how did I solve last time?
2022-01-05

Enums in Angular templates

How to use enum in the html template
2019-01-21
Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).