Translate date long format from English to Portuguese

Asked

Viewed 1,320 times

0

I’m converting a String to Date

SimpleDateFormat dateFormat = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",
                        Locale.ENGLISH);
                Date convertDate = new Date();
                String dd = c.getString(c.getColumnIndex("DATA_NOTICIA");

                try{
                    convertDate = dateFormat.parse(dd);
                }catch(ParseException e){
                    e.printStackTrace();
                }

And passing it to a listview, on the listview it appears like this: Wed Jul 13 16:52:48 GMT 2016 Can you translate this date into Portuguese? I haven’t found a way, someone’s been through it?

1 answer

5


Date presentation format differs from country/language to country/language.

To get the format for the desired country/language you must inform yourself to Simpledateformat its Locale.

Use this method to make Locale changes:

public static String formatDateToLocale(String data, String formato,
                                        Locale localeEntrada, Locale localeSaida) {

    SimpleDateFormat dateFormatEntrada = new SimpleDateFormat(formato, localeEntrada);
    SimpleDateFormat dateFormatSaida = new SimpleDateFormat(formato, localeSaida);

    Date dataOriginal;
    String novoFormato = null;

    try {

        dataOriginal = dateFormatEntrada.parse(data);
        novoFormato = dateFormatSaida.format(dataOriginal);

    } catch (ParseException e) {

        e.printStackTrace();

    }
    return novoFormato;
}

Use like this:

String data = formatDateToLocale("Wed Jul 13 16:52:48 GMT 2016","EE MMM dd HH:mm:ss z yyyy",
                                 Locale.ENGLISH, new Locale("pt","BR"));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.