Some common operations and applications for dates in Java (Date,dateformat,simpledateformat)

Source: Internet
Author: User
Tags dateformat

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.