Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. static void printMonthCalendar(String dateString) throws ParseException {
  2.  
  3. SimpleDateFormat formatDate = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
  4. Date date = formatDate.parse(dateString);
  5.  
  6.  
  7. Calendar cal = new GregorianCalendar();
  8.  
  9. cal.setTime(date);
  10. String month = "";
  11. if (cal.get(Calendar.MONTH) == 0) {
  12. month = "January";
  13. } else if (cal.get(Calendar.MONTH) == 1) {
  14. month = "February";
  15. } else if (cal.get(Calendar.MONTH) == 2) {
  16. month = "March";
  17. } else if (cal.get(Calendar.MONTH) == 3) {
  18. month = "April";
  19. } else if (cal.get(Calendar.MONTH) == 4) {
  20. month = "May";
  21. } else if (cal.get(Calendar.MONTH) == 5) {
  22. month = "June";
  23. } else if (cal.get(Calendar.MONTH) == 6) {
  24. month = "July";
  25. } else if (cal.get(Calendar.MONTH) == 7) {
  26. month = "August";
  27. } else if (cal.get(Calendar.MONTH) == 8) {
  28. month = "September";
  29. } else if (cal.get(Calendar.MONTH) == 9) {
  30. month = "October";
  31. } else if (cal.get(Calendar.MONTH) == 10) {
  32. month = "November";
  33. } else if (cal.get(Calendar.MONTH) == 11) {
  34. month = "December";
  35. }
  36.  
  37. System.out.println(month + " " + cal.get(Calendar.YEAR));
  38. System.out.println(" S M T W T F S");
  39.  
  40. int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
  41. int dayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  42.  
  43. int counter = 0;
  44. int days = 1;
  45. while(days < dayOfWeek) {
  46. System.out.print(" ");
  47. days++;
  48. counter++;
  49. }
  50.  
  51. days =1;
  52. while(days < dayOfMonth){
  53. System.out.printf("%1$2d", days);
  54. counter++;
  55. if (counter >= 7) {
  56. counter = 0;
  57. System.out.println();
  58. } else {
  59. System.out.print(" ");
  60. }
  61. days++;
  62. }
  63. System.out.println();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement