views:

107

answers:

1

Basicaly I want to format a Date object using a specific pattern and the output should be in English. How can I prevent java from translating the output in the system language?

String date = new SimpleDateFormat("EEE MMM dd kk:mm:ss yyyy").format(myDate);
// output is in German:
// Mi Aug 26 16:35:55 2009
+3  A: 

SimpleDateFormat is always localized, it makes no sense otherwise.

You can, however, specify the Locale to use when you build it, e.g.

SimpleDateFormat format = new SimpleDateFormat(
   "EEE MMM dd kk:mm:ss yyyy", 
   Locale.ENGLISH
);
skaffman
Thanks! I have to pass a timestamp to a remote server, that's why I needed "unlocalized" output.
stefita
In that case, I suggest passing in ISO-standard format. JodaTime's ISODateTimeFormat performs that task nicely.
skaffman