Using @I wish I could think of a good
's suggestion, I made the following code that formats date using locale and user settings:
public static String timeDateStringFromTimestamp(Context applicationContext,long timestamp){
String timeDate;
String androidDateTime=android.text.format.DateFormat.getDateFormat(applicationContext).format(new Date(timestamp))+" "+
android.text.format.DateFormat.getTimeFormat(applicationContext).format(new Date(timestamp));
String javaDateTime = DateFormat.getDateTimeInstance().format(new Date(timestamp));
String AmPm="";
if(!Character.isDigit(androidDateTime.charAt(androidDateTime.length()-1))) {
if(androidDateTime.contains(new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM])){
AmPm=" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM];
}else{
AmPm=" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM];
}
androidDateTime=androidDateTime.replace(AmPm, "");
}
if(!Character.isDigit(javaDateTime.charAt(javaDateTime.length()-1))){
javaDateTime=javaDateTime.replace(" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM], "");
javaDateTime=javaDateTime.replace(" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM], "");
}
javaDateTime=javaDateTime.substring(javaDateTime.length()-3);
timeDate=androidDateTime.concat(javaDateTime);
return timeDate.concat(AmPm);
}