Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String pattern = "MMM dd, yyyy hh:mm:ss a";
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
- Date date = simpleDateFormat.parse("Mar 27, 2019 01:50:34 PM");
- Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Colombo"));
- cal.setTime(date);
- int year = cal.get(Calendar.YEAR);
- System.out.println("year : "+year);
- int month = cal.get(Calendar.MONTH);
- System.out.println("month : "+month);
- int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
- System.out.println("day of month : "+dayOfMonth);
- int dayOfWeekInMonth = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
- System.out.println("day of week in month : "+dayOfWeekInMonth);
- int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
- System.out.println("day of week : "+dayOfWeek);
- int hourIn12 = cal.get(Calendar.HOUR);
- System.out.println("hour in 12 : "+hourIn12);
- int hourIn24 = cal.get(Calendar.HOUR_OF_DAY);
- System.out.println("hour in 24 : "+hourIn24);
- int minutes = cal.get(Calendar.MINUTE);
- System.out.println("minutes : "+minutes);
- int seconds = cal.get(Calendar.SECOND);
- System.out.println("seconds : "+seconds);
- // year : 2019
- // month : 2
- // day of month : 27
- // day of week in month : 4
- // day of week : 4
- // hour in 12 : 1
- // hour in 24 : 13
- // minutes : 50
- // seconds : 34
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement