iank
iank

Reputation: 810

Joda DateTimeFormatter giving a mixture of languages

This is super weird.

I'm using a Joda Time DateTimeFormatter, giving the format

EEE MMM d, yyyy h:mm a 'UTC'ZZ

and it's printing

mié may 29, 2013 5:15 PM UTC-06:00

Which seems to be a mixture of Spanish and English.

    formatLocalDateTime(DateTimeFormat.forPattern("EEE MMM d, yyyy h:mm a 'UTC'ZZ"), dateTime)



public static String formatLocalDateTime(final DateTimeFormatter formatter, final DateTime dateTime) {
    if (dateTime == null) {
        return "";
    }
    DateTimeFormatter f = formatter.withLocale(LocaleUtils.toLocale("es_US"));
    f = f.withZone(getTimeZone());

    return f.print(dateTime);
}

I'm completely lost. Any ideas? Thanks!

Upvotes: 0

Views: 1081

Answers (1)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

It's your Locale - you are getting the correct formatting for "es_US" - see, for example, http://www.localeplanet.com/icu/es-US/

If you are expecting US English, use "en_US" If what you want is Spanish (Spain), use "es_ES"

The list of Locales is at http://www.oracle.com/technetwork/java/javase/locales-137662.html

Edit - What you are seeing are the 'short' Day of Week and Month of Year. If you want the 'long' versions, which are both in Spanish in es_US, use the format

"EEEE MMMM d, yyyy h:mm a 'UTC'ZZ"

which will yield

miércoles mayo 29, 2013 5:15 PM UTC-06:00

Upvotes: 2

Related Questions