I am trying to parse a date with a SimpleDateFormat and I encountered a strange behavior.
This Example prints "Sun Jan 01 19:00:32 CET 2012" on my machine:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
public class Test {
public static void main(String[] args) throws ParseException {
System.out.println(new SimpleDateFormat("MMM dd HH:mm:ss YYYY", Locale.ENGLISH).parse("Sep 26 19:00:32 2012"));
}
}
I would expect to have "Wed Sep 26 19:00:32 CET 2012" returned instead.
Is my DateFormat String incorrect?
The year uses small caps y:
System.out.println(new SimpleDateFormat("MMM dd HH:mm:ss yyyy", Locale.ENGLISH).
parse("Sep 26 19:00:32 2012"));
Large cap Y is "Week year" according to javadoc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With