SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String pattern = "MMM dd, yyyy hh:mm:ss a";
  2. SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
  3. Date date = simpleDateFormat.parse("Mar 27, 2019 01:50:34 PM");
  4. Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Colombo"));
  5. cal.setTime(date);
  6. int year = cal.get(Calendar.YEAR);
  7. System.out.println("year : "+year);
  8.  
  9. int month = cal.get(Calendar.MONTH);
  10. System.out.println("month : "+month);
  11.  
  12. int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
  13. System.out.println("day of month : "+dayOfMonth);
  14.  
  15. int dayOfWeekInMonth = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
  16. System.out.println("day of week in month : "+dayOfWeekInMonth);
  17.  
  18. int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
  19. System.out.println("day of week : "+dayOfWeek);
  20.  
  21. int hourIn12 = cal.get(Calendar.HOUR);
  22. System.out.println("hour in 12 : "+hourIn12);
  23.  
  24. int hourIn24 = cal.get(Calendar.HOUR_OF_DAY);
  25. System.out.println("hour in 24 : "+hourIn24);
  26.  
  27. int minutes = cal.get(Calendar.MINUTE);
  28. System.out.println("minutes : "+minutes);
  29.  
  30. int seconds = cal.get(Calendar.SECOND);
  31. System.out.println("seconds : "+seconds);
  32.  
  33. // year : 2019
  34. // month : 2
  35. // day of month : 27
  36. // day of week in month : 4
  37. // day of week : 4
  38. // hour in 12 : 1
  39. // hour in 24 : 13
  40. // minutes : 50
  41. // seconds : 34
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top