I need to convert a Joda-Time DateTime into a String, in the following format:
Sat, 1 Jan 2011 00:00:00
I’m using this code:
DateTimeFormatter f = DateTimeFormat.forPattern("E, d MMM yyyy HH:mm:ss");
f.withLocale(Locale.US);
System.out.println(DateTime.now().toString(f));
My output is however:
wo, 20 jun. 2012 00:03:31
So the problems are:
- The output is in Dutch instead of English (‘wo’ for ‘wed’)
- The month has a period
How can I do this correctly?
DateTimeFormatter.withLocale returns a new DateTimeFormatter. So you need to do this:
Alternatively (equivalently):