Skip to content

Instantly share code, notes, and snippets.

@Fatimamostafa
Last active June 1, 2018 10:23
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 Fatimamostafa/9351b62520dfc33010077053c8447bcd to your computer and use it in GitHub Desktop.
Save Fatimamostafa/9351b62520dfc33010077053c8447bcd to your computer and use it in GitHub Desktop.
ISO8601 date format parsing
//Date converter
public static String dateConverter(String dateFromApi) {
TimeZone tz = Calendar.getInstance().getTimeZone();
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
inputFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat outputFormat = new SimpleDateFormat("dd MMM h:mm a");
Date date = null;
try {
date = inputFormat.parse(dateFromApi);
} catch (ParseException e) {
e.printStackTrace();
}
String formattedDate = outputFormat.format(date);
String str = formattedDate.replace("AM", "am").replace("PM", "pm");
return str; // 13 Oct 10:34 am
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment