I'm trying to read data from RSS feeds and one of the fields is when the feed was last updated. I'm using something similar to this:
Date date;
String output;
SimpleDateFormat formatter;
String pattern = "EEE, dd MMM, HH:mm:ss Z";
formatter = new SimpleDateFormat(pattern, Locale.ENGLISH);
date = formatter.parse("Wed, 25 Mar 2020 08:00:00 +0200");
output = date.toString();
System.out.println(pattern + " | " + output);
but I get this error:
Exception in thread "main" java.text.ParseException: Unparseable date: "Wed, 25 Mar 2020 08:00:00 +0200"
at java.text.DateFormat.parse(DateFormat.java:366)
at HelloWorld.main(HelloWorld.java:16)
yyyyis missing in the format string. There is also a comma after the month which is not in your input string. Try this:EEE, dd MMM yyyy HH:mm:ss ZSimpleDateFormatandDate. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead useOffsetDateTimeandDateTimeFormatter, both from java.time, the modern Java date and time API.