Package MyCalendar;
Import Java.text.DateFormat;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.GregorianCalendar;
Import Java.util.Scanner;
/**
* Visual Calendar
* @author Iwang
*
*/
public class MyCode {
public static void Main (string[] args) {
System.out.println ("Please Enter Date: (by Format: 2030-1-1)");
Scanner str = new Scanner (system.in);
String temp = Str.nextline ();
String temp = "2016-11-13";
DateFormat format = new SimpleDateFormat ("Yyyy-mm-dd");
try {
Date date = Format.parse (temp);
Calendar calendar = new GregorianCalendar ();
Calendar.settime (date);
int day = Calendar.get (calendar.date);
Calendar.set (calendar.date, 1);
System.out.println (Calendar.get (Calendar.day_of_week)); What's the number of a week?
int kong = Calendar.get (Calendar.day_of_week)-1;
System.out.println (Calendar.getactualmaximum (calendar.date)); What number is the last day?
int maxdate = Calendar.getactualmaximum (calendar.date);
System.out.println ("day \ t a \ Two \ three \ four \ t five \ t six \ t");
for (int k=0;k< (Calendar.get (Calendar.day_of_week)-1); k++) {
System.out.print ("" + "\ T");
}
System.out.println ("day \ t a \ Two \ three \ four \ t five \ t six \ t");
int j = 0;
for (int i=1;i<=maxdate;i++) {
if (i!=day) {
System.out.print (i+ "\ t");
}else
if (i==day) {
System.out.print ("[" +i+ "]\t");
}
System.out.print (i+ "\ t");
j + +;
int w = calendar.get (Calendar.day_of_week);
if (/*j%7==0*/w = = Calendar.saturday) {
System.out.println ();
}
Calendar.add (calendar.date, 1);
}
} catch (ParseException e) {
E.printstacktrace ();
}
}
}
Java Learning notes-calendar programs