I'm trying to convert dates generated by Java's toString() function back into date objects. However the behaviour doesn't match what I'm expecting.
I've tried the following code:
public static void main(String[] args) {
SimpleDateFormat sdfDate = new SimpleDateFormat("E MMM dd HH:mm:ss zzz YYYY");
Date now = new Date();
String strDate = sdfDate.format(now);
try {
System.out.println(strDate+"\n"+sdfDate.parse(strDate).toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
However when I run the above I'm getting the following output:
Mon Jul 25 16:58:04 BST 2016
Mon Jan 04 15:58:04 GMT 2016
I understand why the timezone is reverting to GMT, however I'm confused its interpretation of the month and day. I'm assuming I've messed something up in the Date format string, but I can't tell what.
I've also tried it with "EEE MMM dd HH:mm:ss zzz YYYY" but I get the same behaviour. Can anyone tell me what I'm doing wrong please?