Translate date format from English to Portuguese

0

I'm converting a String to Data

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, in the listView it looks like this: Wed Jul 13 16:52:48 GMT 2016 Can you translate this date into Portuguese? I did not find a way, did anyone ever go through this?

    
asked by anonymous 25.10.2016 / 20:03

1 answer

4

The format for displaying dates differs from country / language to country / language.

In order to obtain the format for the desired country / language you must inform 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 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"));
    
25.10.2016 / 20:45