1 ImportJava.text.DateFormat;2 ImportJava.text.SimpleDateFormat;3 Importjava.util.Date;4 ImportJava.util.Calendar;5 ImportJava.util.GregorianCalendar;6 7 Public classOct_18_timeanddateformat {8 9 Public Static voidMain (string[] args) {Ten One //The date class is contained within the Java.util package and is required to include the file ADate d1=NewDate (); -String temp=d1.togmtstring ();//use D1.togmtstring () to get a GMT string. - System.out.println (temp); theSystem.out.println (D1.tostring ());//Beijing Time - -Date d2=NewDate (); - + /*using System.currenttimemillis () to get a long integer data (in milliseconds), - It is the difference from the 19701-month 1st 0 o'clock (Linux official release time)*/ + Longtemp1=System.currenttimemillis (); A System.out.println (TEMP1); at -Date d3=NewDate (); -System.out.println (D3.tostring ());//Beijing Time -System.out.println (D3.tolocalestring ());//local time. -System.out.println (D3.getdate ());//get the current time in the month of the week. -System.out.println (D3.getmonth () +1);//the number of months starts from 0 to +1 to get the current month. inSystem.out.println (D3.gethours ());//get the first few hours of the day. -System.out.println (D3.getyear () +1900);//getYear () +1900 Gets the current time to + - /*Dateformat,simpledateformat () completes the conversion of the string to the time, which is contained in the Java.text package, when it needs to include the file*/ theDateFormat df1=NewSimpleDateFormat ("Yyyy-mm-dd");//note here that ' mm ' cannot be written as ' mm ', and lowercase is the number of minutes. * Longt=System.currenttimemillis (); $ Longt2=000000000000000l;Panax NotoginsengSystem.out.println (Df1.format (t));//apply DF1 format to print out as 2014-10-18 - the //here ' hh ' lowercase means 12-hour system, changed to ' HH ' for 24-hour system. +DateFormat df2=NewSimpleDateFormat ("yyyy mm month DD day, Hh:mm:ss"); A System.out.println (Df2.format (T2)); the System.out.println (Df2.format (t)); + -DateFormat df3=NewSimpleDateFormat ("yyyy mm month DD day, E HH:MM:SS, your time zone is: ZZ, this week is the first W week of the Year, the month of the week, the year d."). "); $ System.out.println (Df3.format (t)); $ - -GregorianCalendar gc=NewGregorianCalendar (); the //Determines whether a year is a leap years. -SYSTEM.OUT.PRINTLN (Gc.isleapyear (2014));WuyiSystem.out.println (Gc.isleapyear (2000)); the - } Wu - } About $ - - - AWriter:hruinger
Writer:hruinger
Some common operations and applications for dates in Java (Date,dateformat,simpledateformat)