Im struggling understanding whats happening when I select a date from my angular calendar for example "29/05/2021" and send it to my backend it arrives as "Fri May 28 19:00:00 COT 2021" one day less.
In my calendar im setting the date timezone with pipes as utc-5 which is my timezone like this:
{{todo.targetDate | date: 'yyyy-MM-dd':'utc-5' | uppercase}}
when I do console.log(todo.targetDate) before sending the JSON which contains the date I can see it prints "2021-05-29" which is correct.
But when it arrives at my backend (Java) when I print I get "Fri May 28 19:00:00 COT 2021", I think the problem is im only changing the date format visually in angular, but not its value, but since the console prints the correct format in angular, im confused now.. can you plesae tell me any hint to find out the problem? Im learning front end skills so please be soft.
EDIT:
Maybe the problem is more in my backend, here is an image of how the date looks inside the JSON object which is very strange:
And here is my code in the backend java:
@PutMapping(path = "/jpa/users/{username}/todos/{id}")
public ResponseEntity<Todo> updateTodo(@PathVariable String username, @PathVariable long id, @RequestBody Todo todo)
throws ParseException {
System.out.println(todo.getTargetDate());
// Fri May 28 19:00:00 COT 2021
LocalDate fechaBien = todo.getTargetDate().toInstant().atZone(ZoneId.of("UTC-05:00")).toLocalDate();
System.out.println(fechaBien);
// 2021-05-28
// I added 1 day to make it 2021-05-29 but this is bad because then at angular it appears as 2021-05-30 XD
fechaBien = fechaBien.plusDays(1);
// Then I parse the localdate to Date because thats the type of this property
todo.setTargetDate(Date.from(fechaBien.atStartOfDay(ZoneId.of("America/Bogota")).toInstant()));
System.out.println(todo.getTargetDate());
// Sat May 29 00:00:00 COT 2021
return new ResponseEntity<Todo>(todo, HttpStatus.OK);
}