Inconsistent date format for German

The following code produces different output in Android and standard jdk

final DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.GERMAN); final String today = df.format(new Date()); 

Output:

Android: Mi., 24 Jul 2013 12:33:12 +0200

Standard jdk: Mi, 24 Jul 2013 12:33:12 +0200

On the server side, it throws a parsing exception, any idea?

+2
java android datetime
source share
2 answers

Use the standard time format by date. JDK does not support all locales. Therefore, it is safe to use Locale.US, especially useful when exchanging data on the platform.

+2
source share

I can offer a workaround:

  SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.GERMAN); DateFormatSymbols dfs = df.getDateFormatSymbols(); String[] swd = {"", "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"}; dfs.setShortWeekdays(swd); df.setDateFormatSymbols(dfs); 

now it will format dates in

 Mi, 24 Jul 2013 12:33:12 +0200 

in standard Java and Android

+3
source share

All Articles