Some of the APIs involved:
Calendar Calendar = Calendar. getinstance ();
Calendar. getTime ();
Calendar. settime (date);
Calendar. Set (calendar.year,2000);
Calendar. Get (calendar.date);
Calendar. Add (Calendar.day_of_year, 10);
Calendar. Getactualmaximum (Calendar.day_of_month);
Calendar1. After (CALENDAR2);
Calendar. Gettimeinmillis ();
SimpleDateFormat SDF = new SimpleDateFormat ();
Sdf. parse ();
Sdf. format ();
SimpleDateFormat SDF = new SimpleDateFormat ("yyyy-mm-dd HH:mm:ss E");
String strtime = sdf. format (date);
Date = SDF. Parse (Strtime);
For example, the following code is shown:
1 Packagetest;2 3 Importjava.text.ParseException;4 ImportJava.text.SimpleDateFormat;5 ImportJava.util.Calendar;6 Importjava.util.Date;7 8 Public classDatedemo {9 Ten Public Static voidMain (string[] args)throwsParseException { OneDate Date =NewDate (); A - //current time millisecond value, long type - LongNumtime =date.gettime (); the System.out.println (numtime); - - //constructs SimpleDateFormat objects in "Yyyy-mm-dd HH:mm:ss E" format -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss E"); + - //generates a string time in SDF format (specified in the constructor method) based on the date type Object +String Strtime =Sdf.format (date); A System.out.println (strtime); at - //generates a date type object from the string strtime in the format in SDF (specified in the constructor method) -Date =Sdf.parse (strtime); - System.out.println (date); - - //Calendar is an abstract class and cannot be generated directly from new inCalendar Calendar =calendar.getinstance (); -Calendar calendar2 =Calendar; toSYSTEM.OUT.PRINTLN (Calendar);//This output is straightforward to read, java.util.gregoriancalendar[time=1504450592066,arefieldsset=true,areallfieldsset=true,lenient= True,zone=sun.util.calendar.zoneinfo[id= "gmt+08:00", offset=28800000,dstsavings=0,usedaylight=false,transitions =0,lastrule=null],firstdayofweek=1,minimaldaysinfirstweek=1,era=1,year=2017,month=8,week_of_year=36,week_of_ Month=2,day_of_month=3,day_of_year=246,day_of_week=1,day_of_week_in_month=1,am_pm=1,hour=10,hour_of_day=22, Minute=56,second=32,millisecond=66,zone_offset=28800000,dst_offset=0] + - //Get Date Object theDate =calendar.gettime (); * $ //set time in date to calendarPanax Notoginseng calendar.settime (date); - the //Get + Calendar.get (calendar.year); A the //Set +Calendar.set (calendar.month, 0); - $ //Increase $Calendar.add (Calendar.day_of_year, 10); - - //Specifies the maximum value that a calendar field may have. The maximum number of days in the current month in this sentence. the Calendar.getactualmaximum (calendar.day_of_month); - Wuyi the - //Boolean type that determines whether the calendar1 time is after Calendar2 Wu Calendar.after (CALENDAR2); - About //gets the millisecond value that returns a long type $ Calendar.gettimeinmillis (); - - - } A +}
Java Notes------Date API