Name

Date

Synopsis

This class represents dates and times and lets you work with them in a system-independent way. You can create a Date by specifying the number of milliseconds from the epoch (midnight GMT, January 1st, 1970) or the year, month, date, and, optionally, the hour, minute, and second. Years are specified as the number of years since 1900. If you call the Date constructor with no arguments, the Date is initialized to the current time and date. The instance methods of the class allow you to get and set the various date and time fields, to compare dates and times, and to convert dates to and from string representations. As of Java 1.1, many of the date methods have been deprecated in favor of the methods of the Calendar class.

java.util.Date

Figure 16-13. java.util.Date

public class Date implements Serializable, Cloneable, Comparable<Date> {
// Public Constructors
     public Date( );  
     public Date(long date);  
#    public Date(String s);  
#    public Date(int year, int month, int date);  
#    public Date(int year, int month, int date, int hrs, int min);  
#    public Date(int year, int month, int date, int hrs, int min, int sec);  
// Public Instance Methods
     public boolean after(Date when);  
     public boolean before(Date when);  
     public long getTime( );                             default:1101702237486
     public void setTime(long time);  
// Methods Implementing Comparable
                  1.2  public int compareTo(Date anotherDate);  
// Public Methods Overriding Object ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.