Robert Gurjiev :
I have this exception with this code:
[email protected]: 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.
dieter :
You have to set Locale, like this:
SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
because of Fri Dec in your input string and your default locale is probably not english
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=349091&siteId=1