1. Calculate the maximum number of days in a January:
Calendar time=calendar.getinstance ();
time.clear ();
Time.set (calendar.year,year);//year is int
time.set (calendar.month,i-1);/Note that Calendar object defaults to January of 0
int Day=time.getactualmaximum (calendar.day_of_month);//Days of the Month
Note: Before using the Set method, you must clear it, otherwise many of the information will be inherited from the system current time
Conversion of 2.Calendar and date:
(1) Calendar conversion to date:
Calendar cal=calendar.getinstance ();
Date date=cal.gettime ();
(2) Date converted to calendar:
Date Date=new date ();
Calendar cal=calendar.getinstance ();
cal.settime (date);
3. Format the output date time (more of this):
Date Date=new date ();
SimpleDateFormat df=new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
String Time=df.format (date);
System.out.println (time);
4. Calculation of the first week of the year:
(1) to calculate the day of the year is the first week:
Calendar cal=calendar.getinstance ();
Cal.set (Calendar.year, 2006);
Cal.set (Calendar.month, 8);
Cal.set (Calendar.day_of_month, 3);
int Weekno=cal.get (calendar.week_of_year);