Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void printMonthCalendar(String dateString) throws ParseException {
- SimpleDateFormat formatDate = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
- Date date = formatDate.parse(dateString);
- Calendar cal = new GregorianCalendar();
- cal.setTime(date);
- String month = "";
- if (cal.get(Calendar.MONTH) == 0) {
- month = "January";
- } else if (cal.get(Calendar.MONTH) == 1) {
- month = "February";
- } else if (cal.get(Calendar.MONTH) == 2) {
- month = "March";
- } else if (cal.get(Calendar.MONTH) == 3) {
- month = "April";
- } else if (cal.get(Calendar.MONTH) == 4) {
- month = "May";
- } else if (cal.get(Calendar.MONTH) == 5) {
- month = "June";
- } else if (cal.get(Calendar.MONTH) == 6) {
- month = "July";
- } else if (cal.get(Calendar.MONTH) == 7) {
- month = "August";
- } else if (cal.get(Calendar.MONTH) == 8) {
- month = "September";
- } else if (cal.get(Calendar.MONTH) == 9) {
- month = "October";
- } else if (cal.get(Calendar.MONTH) == 10) {
- month = "November";
- } else if (cal.get(Calendar.MONTH) == 11) {
- month = "December";
- }
- System.out.println(month + " " + cal.get(Calendar.YEAR));
- System.out.println(" S M T W T F S");
- int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
- int dayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
- int counter = 0;
- int days = 1;
- while(days < dayOfWeek) {
- System.out.print(" ");
- days++;
- counter++;
- }
- days =1;
- while(days < dayOfMonth){
- System.out.printf("%1$2d", days);
- counter++;
- if (counter >= 7) {
- counter = 0;
- System.out.println();
- } else {
- System.out.print(" ");
- }
- days++;
- }
- System.out.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement