Skip to content

Instantly share code, notes, and snippets.

@Tarelochkin
Last active July 15, 2017 18:29
Show Gist options
  • Save Tarelochkin/1a0805baa3b0f271f21c19cc7debe5c8 to your computer and use it in GitHub Desktop.
Save Tarelochkin/1a0805baa3b0f271f21c19cc7debe5c8 to your computer and use it in GitHub Desktop.
Format date with a pattern: 2017-04-12T05:41:46Z for Medium UK locale
String dateString = "2017-04-12T05:41:46Z"
SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
Date convertedDate;
String formattedDate = "";
try {
convertedDate = sourceFormat.parse(dateString);
//will return "12 Apr 2017"
formattedDate = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.UK).format(convertedDate);
} catch (ParseException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment