Skip to content

Instantly share code, notes, and snippets.

@seupedro
Created June 2, 2018 13:40
Show Gist options
  • Save seupedro/ee9015c74d8c55fa11d5af6592df2d4f to your computer and use it in GitHub Desktop.
Save seupedro/ee9015c74d8c55fa11d5af6592df2d4f to your computer and use it in GitHub Desktop.
Formate date based on User Locale on Android
String weddingDate = "26/02/1974";
/* Specify which format is */
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = null;
try {
/* Parse to date object */
date = sdf.parse(weddingDate);
} catch (ParseException e) {
// handle exception here !
}
/* Format based on User Locale */
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
String s = dateFormat.format(date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment