Skip to content

Instantly share code, notes, and snippets.

@AHarazim
Created August 8, 2014 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AHarazim/f773097cfd1308227556 to your computer and use it in GitHub Desktop.
Save AHarazim/f773097cfd1308227556 to your computer and use it in GitHub Desktop.
Localised Date in Andorid
public String formatDate(Date date, boolean withTime) {
String result = "";
DateFormat dateFormat;
if (date != null) {
try {
String format = Settings.System.getString(mContext.getContentResolver(), Settings.System.DATE_FORMAT);
if (TextUtils.isEmpty(format)) {
dateFormat = android.text.format.DateFormat.getDateFormat(mContext);
} else {
dateFormat = new SimpleDateFormat(format);
}
result = dateFormat.format(date);
if (withTime) {
dateFormat = android.text.format.DateFormat.getTimeFormat(mContext);
result += " " + dateFormat.format(date);
}
} catch (Exception e) {
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment