class Date Methods

class Date Methods

class Date Methods

Summary: By the end of this tutorial "class Date Methods", you will come to know how to use Java Date class methods.

Introduction to class Date Methods

java.util.Date class constructor is used to print the system date. It comes with many methods to manipulate the date. But these methods are deprecated in favor of java.util.Calendar class introduced in JDK 1.1. Calendar class supports DateFormat class needed for internalization.

To use Date class, following concepts are to be remembered.

  1. Add 1900 (known as epoch year) to the year returned by the Date class to get the correct year. That is, for 2011, the date returns 111.
  2. Months are numbered to 0 to 11. That is 0, returned by the Date class, should be learnt as January.
  3. Month dates are numbered 1 to 31.
  4. Hours are given as 0 to 23. The early morning 1.00 AM is returned as 0.0 hour.
  5. Minutes are numbered as 0 to 59.
  6. Seconds are printed as 0 to 60 (if 61 is printed, think it is a leap second).

Following is the class signature as defined in the java.util package.

public class Date extends Object implements Serializable, Cloneable, Comparable

Following program explains a few class Date Methods.

class Date Methods

The month is printed as 0; it is January (0+1). The day 3 means, Wednesday. The year 111 means 2011.

Observe the compilation warning message in the screenshot. It is a deprecation warning and an advice not use Date class and use Calendar class.

Leave a Reply

Your email address will not be published. Required fields are marked *