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
Convert date to different format with Format CellsSelect the dates you want to convert, right click to select Format Cells from context menu. 2. In the Format Cells dialog, under Number tab, select Date from Category list, and then select one format you want to convert to from the right section.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With