I'm trying to move some processing from SimpleDateFormat
to the new java.time
packages.
In the following example:
final String str = "28/11/2016 11:58:51 AM UTC (date)";
final String format = "dd/MM/yyyy hh:mm:ss a z";
System.out.println(new SimpleDateFormat(format).parseObject(str));
System.out.println(LocalDateTime.parse(str, DateTimeFormatter.ofPattern(format)));
SimpleDateFormat
parses the String, but LocalDateTime
throws a DateTimeParseException
.
The part in brackets is variable, so SimpleDateFormat
's approach works well. Is there a way of making LocalDateTime
have this behaviour?