Created
March 29, 2017 05:23
-
-
Save itsmejkumar/e87eae4b5b67572e1468466a89fc5faf to your computer and use it in GitHub Desktop.
Date and Time Formatting Android
This file contains hidden or 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
| private String getMonth(String date) throws ParseException { | |
| Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(date); | |
| Calendar cal = Calendar.getInstance(); | |
| cal.setTime(d); | |
| String monthName = new SimpleDateFormat("MMM").format(cal.getTime()); | |
| return monthName; | |
| } | |
| private String getDate(String date) throws ParseException{ | |
| Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(date); | |
| Calendar cal = Calendar.getInstance(); | |
| cal.setTime(d); | |
| String dateName = new SimpleDateFormat("dd").format(cal.getTime()); | |
| return dateName; | |
| } | |
| private String getYear(String date) throws ParseException{ | |
| Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(date); | |
| Calendar cal = Calendar.getInstance(); | |
| cal.setTime(d); | |
| String yearName = new SimpleDateFormat("yyyy").format(cal.getTime()); | |
| return yearName; | |
| } | |
| private String getTime(String date) throws ParseException{ | |
| Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(date); | |
| Calendar cal = Calendar.getInstance(); | |
| cal.setTime(d); | |
| String timeName = new SimpleDateFormat("hh:mm a").format(cal.getTime()); | |
| return timeName; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment