Date Comparison Java Help

Date Comparison

There are three ways to compare two Date objects. First; you can use getTime( ) to obtain the number of milliseconds that have elapsed since midnight, January 1, 1970, for both objects and then compare these two values. Second, you can use the methods bcfore( ), after( ), and equals( ). Because the 12th of the month comes before.the 18th, for example, new Date(99, 2, 12).bcfore(new Date (99, 2, 18)~returns true. Finally, you can use the compareTo( ) method, which is defined by the Comparable interface and implemented by Date:

Calendar 

The abstract Calendar class provides a set of methods that allows you to convert a time in milliseconds to.a number of useful components of the type of' information that cari be provided are: year, month, day, hour, minute, and second. It is intended that subclasses of Calendar will provide the specific functionality to interpret time information according to their own rules. This is one aspect of the Java class library that.enables you to write programs that can' operate in several International environments. An example of secular subclass is Regular Calendar. Calendar provides no public constructors. . Calendar defines several protected instance variables. 'ar!)Fields Sct is.a boolean that indicates if the time components have been set. fields is an array of ints that holds the components of the time. isSet is a boolean array that indicates if a specific lillie component has been 59. time is a long that holds the current time for this object. isTimeSet is a boolean that indicates if the current time has been set. Some commonly used methods defined . Calendar defines the following int constants, which are used when you get or set components of the calendar.

Posted on September 17, 2014 in java.util More Utility Classes

Share the Story

About the Author

Back to Top
Share This