I have this exception with this code:
java.text.SimpleDateFormat@42ee54java.text.ParseException: Unparseable date: "Fri Dec 25 02:00:00 EET 2020"
@PostMapping
public ResponseEntity<?> addEvent(@Valid @RequestBody Event event) {
try {
SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
format1.parse(String.valueOf(event.getDate()));
format1.setLenient(false);
eventService.save(event);
return new ResponseEntity<>(event, HttpStatus.CREATED);
} catch (IllegalArgumentException | ParseException e) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
Due to date format is defined correctly. What can be wrong here? Thanks in advance.