Date class

The class Date represents a specific instant in time, with millisecond precision.

The following representations are used when accepting or returning year, month, date, hours, minutes, and seconds values.

A date may be specified as January 32 and is interpreted as meaning February 1.

ConstructorSummary
Date()Creates a Date object and initializes it with the time at which it was allocated.
Date(long date)Creates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Compare two Date value

ReturnMethodSummary
booleanafter(Date when)Tests if this date is after the specified date.
booleanbefore(Date when)Tests if this date is before the specified date.
intcompareTo(Date anotherDate)Compares two Dates for ordering.
booleanequals(Object obj)Compares two dates for equality.

Convert date value to long value in milliseconds

ReturnMethodSummary
longgetTime()Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
voidsetTime(long time)Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Convert Date value to String

ReturnMethodSummary
StringtoString()Converts this Date object to a String of the form:
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.