Date Time Processing class

Source: Internet
Author: User

java.util.Date class , default format: Thu 21:32:59 CST 2016, the "Day of the week date time China standard Time year" format is not very friendly.

Java.text.SimpleDateFormate class : The class that formats the time, using the following:
----------------------------------output time by format

Date D=new date ();
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
System.out.println (Sdf.format (d));

----------------------------------Convert string time to date class

String s1= "2016-02-25 09:39:02";
D=sdf.parse (S1);
System.out.println (d);

------------------------------------date is heavily criticized, the Calendar class is recommended instead of date

The most important role of the date class is to get the current time, while the class also has set time and some other functions, but because of its own design problems, these methods have been criticized many, not recommended, it is recommended to use the Calendar class for time and date processing.

The Java.util.Calendar class is an abstract class that can get a Calendar object by calling the getinstance () static method, which is initialized by the current datetime, which means the current time by default, such as Calendar C = Calendar.getinstance (); then get the datetime information by calling the Get () method, the parameter is the value of the field that needs to be obtained, calendar.year, and so on as the static constant defined in the Calendar class.

The Calendar class provides the GetTime () method to get the Date object, complete the calendar and date conversions, and the Gettimeinmillis () method to get the time value of this calendar, in milliseconds

Date Time Processing class

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.