JAVA Date Type Data comparison sizing method

Source: Internet
Author: User
Tags dateformat
Two variables of the date type can be compared by the CompareTo method. The description of this method is this: if the parameter date equals this date, the value 0 is returned, and if this date precedes the date parameter, a value less than 0 is returned, and if this date is after the date parameter, a value greater than 0 is returned.
The actual comparison is the number of milliseconds since January 1, 1970 00:00:00 GMT. The greater the number of milliseconds the greater the time.
String DateStr1 = "2014-08-21 10:20:16";
String DateStr2 = "2014-08-27 15:50:35";
DateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date dateTime1 = Dateformat.parse (DATESTR1);
Date dateTime2 = Dateformat.parse (DATESTR2);
int i = Datetime1.compareto (dateTime2);
System.out.println (i < 0);

JAVA Date Type Data comparison sizing method

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.