Java Object-oriented _ Common class Library api--date Operation class

Source: Internet
Author: User
Tags dateformat

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

Related Article

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.