Data class
Class data represents a specific moment, accurate to milliseconds, which is the current time when the program is running
Data data=new data ();//Instantiate the data object representing the current time
Calendar class
Calendar class, which can be used to display the time exactly in milliseconds.
Two types of instantiation
Calendar c=calendar.getinstance ();//calendar class is an abstract class and cannot be directly new
Calendar c=new GregorianCalendar ();
DateFormat class and sub-class SimpleDateFormat
Cases:
1 ImportJava.text.SimpleDateFormat;2 Importjava.util.Date;3 ImportJava.util.Calendar;4 ImportJava.text.DateFormat;5 6 7 Public classDatautiles {8 9 /**Ten * @paramargs One */ A Public Static voidMain (string[] args) { - //TODO auto-generated Method Stub -Date d=NewDate (); the System.out.println (d); - -Calendar c=calendar.getinstance (); - intYear=c.get (calendar.year);//Get year + intMonth=c.get (calendar.month) +1;//Month - intDay=c.get (Calendar.day_of_month);//Day + intWeek=c.get (Calendar.day_of_week)-1;//Week A intHour=c.get (Calendar.hour_of_day);//when at intMinute=c.get (Calendar.minute);//points - intSecond=c.get (Calendar.second);//seconds -String[] weeks={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; -SYSTEM.OUT.PRINTLN (year+ "year" +month+ "month" +day+ "Day" + "+weeks[week]+hour+": "+minute+": "+second); - //use time date format mode -DateFormat df=NewSimpleDateFormat ("yyyy mm month DD Day HH:MM:SS SSS E"); inString Nowdate=df.format (NewDate ()); - System.out.println (nowdate); to + LongData2=system.currenttimemillis ();//represents the current system time (in milliseconds) - System.out.println (data2); the } * $}
Java Object-oriented _ Common class Library api--date Operation class