Last active
June 1, 2018 10:23
-
-
Save Fatimamostafa/9351b62520dfc33010077053c8447bcd to your computer and use it in GitHub Desktop.
ISO8601 date format parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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