I am displaying the date and time in Android with this format: 2013-06-18 12:41:24
How can I change it to the following format? 18-jun-2013 12:41 pm
Here is working code
public String parseDateToddMMyyyy(String time) { String inputPattern = "yyyy-MM-dd HH:mm:ss"; String outputPattern = "dd-MMM-yyyy h:mm a"; SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern); SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern); Date date = null; String str = null; try { date = inputFormat.parse(time); str = outputFormat.format(date); } catch (ParseException e) { e.printStackTrace(); } return str; }
Documentation: SimpleDateFormat | Android Developers
1.4m articles
1.4m replys
5 comments
57.0k users