Translate long date format from English to Portuguese
I am 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, in the listView it appears like this: Wed Jul 13 16:52:48 GMT 2016
Can you translate this date into Portuguese?
I didn't find a way, has anyone ever been through this?
0
1 answers
Date display format differs from country / language to country / language.
To obtain the format for the desired country/language you must inform SimpleDateFormat the respective 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"));
4
Author: ramaral, 2016-10-25 19:21:54