Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util

Class Date

java.lang.Object
|
+--java.util.Date

All Implemented Interfaces:

Cloneable, Comparable, Serializable


public class Date

extends Object

implements Cloneable, Comparable, Serializable

This class represents a specific time in milliseconds since the epoch. The epoch is 1970, January 1 00:00:00.0000 UTC. Date is intended to reflect universal time coordinate (UTC), but doesn't handle the leap seconds. Prior to jdk 1.1 this class was the sole Time class and had also calendar functionality. But this can't be localized, so a new Calendar class was created, that you should use instead. The functions which get or return a year, month, day etc. are all deprecated and shouldn't be used. Use Calendar instead.

Authors:See Also:

Constructor Summary

Date()

Creates a new Date Object representing the current time.
Date(long time)

Creates a new Date Object representing the given time.
Date(int year, int month, int day)

Creates a new Date Object representing the given time.
Date(int year, int month, int day, int hour, int min)

Creates a new Date Object representing the given time.
Date(int year, int month, int day, int hour, int min, int sec)

Date(java.lang.String s)

Creates a new Date from the given string representation.

Method Summary

static longUTC(int year, int month, int date, int hrs, int min, int sec)

booleanafter(java.util.Date when)

Tests if this date is after the specified date.
booleanbefore(java.util.Date when)

Tests if this date is before the specified date.
java.lang.Objectclone()

intcompareTo(java.util.Date when)

Compares two dates.
intcompareTo(java.lang.Object obj)

Compares this Date to another.
booleanequals(java.lang.Object obj)

Compares two dates for equality.
intgetDate()

intgetDay()

intgetHours()

intgetMinutes()

intgetMonth()

intgetSeconds()

longgetTime()

Gets the time represented by this Object
intgetTimezoneOffset()

intgetYear()

inthashCode()

static longparse(java.lang.String string)

Parse a String and return the time it represents.
voidsetDate(int date)

Sets the date to the given value, not changing the other fields.
voidsetHours(int hours)

Sets the hours to the given value, not changing the other fields.
voidsetMinutes(int minutes)

Sets the minutes to the given value, not changing the other fields.
voidsetMonth(int month)

Sets the month to the given value, not changing the other fields.
voidsetSeconds(int seconds)

Sets the seconds to the given value, not changing the other fields.
voidsetTime(long time)

Sets the time which this Object should represented.
voidsetYear(int year)

Sets the year to year minus 1900, not changing the other fields.
java.lang.StringtoGMTString()

Format this object in a standard format in the GMT timezone.
java.lang.StringtoLocaleString()

Format this object in a locale-specific way.
java.lang.StringtoString()

Constructor Details

Date

public Date()

Creates a new Date Object representing the current time.


Date

public Date(int year, int month, int day)

Creates a new Date Object representing the given time.

Parameters:


Date

public Date(int year, int month, int day, int hour, int min)

Creates a new Date Object representing the given time.

Parameters:


Date

public Date(int year, int month, int day, int hour, int min, int sec)

Parameters:


Date

public Date(java.lang.String s)

Creates a new Date from the given string representation. This does the same as new Date(Date.parse(s))

Parameters:

See Also:


Date

public Date(long time)

Creates a new Date Object representing the given time.

Parameters:


Method Details

UTC

public static long UTC(int year, int month, int date, int hrs, int min, int sec)

Parameters:

Returns:


after

public boolean after(java.util.Date when)

Tests if this date is after the specified date.

Parameters:

Returns:


before

public boolean before(java.util.Date when)

Tests if this date is before the specified date.

Parameters:

Returns:


clone

public Object clone()


compareTo

public int compareTo(java.lang.Object obj)

Compares this Date to another. This behaves like compareTo(Date), but it may throw a ClassCastException

Parameters:

Returns:

Throws:


compareTo

public int compareTo(java.util.Date when)

Compares two dates.

Parameters:

Returns:


equals

public boolean equals(java.lang.Object obj)

Compares two dates for equality.

Parameters:

Returns:


getDate

public int getDate()

Returns:


getDay

public int getDay()

Returns:


getHours

public int getHours()

Returns:


getMinutes

public int getMinutes()

Returns:


getMonth

public int getMonth()

Returns:


getSeconds

public int getSeconds()

Returns:


getTime

public long getTime()

Gets the time represented by this Object

Returns:


getTimezoneOffset

public int getTimezoneOffset()

Returns:


getYear

public int getYear()

Returns:


hashCode

public int hashCode()


parse

public static long parse(java.lang.String string)

Parse a String and return the time it represents.

Parameters:


setDate

public void setDate(int date)

Sets the date to the given value, not changing the other fields.

Parameters:


setHours

public void setHours(int hours)

Sets the hours to the given value, not changing the other fields.

Parameters:


setMinutes

public void setMinutes(int minutes)

Sets the minutes to the given value, not changing the other fields.

Parameters:


setMonth

public void setMonth(int month)

Sets the month to the given value, not changing the other fields.

Parameters:


setSeconds

public void setSeconds(int seconds)

Sets the seconds to the given value, not changing the other fields.

Parameters:


setTime

public void setTime(long time)

Sets the time which this Object should represented.

Parameters:


setYear

public void setYear(int year)

Sets the year to year minus 1900, not changing the other fields.

Parameters:


toGMTString

public String toGMTString()

Format this object in a standard format in the GMT timezone.


toLocaleString

public String toLocaleString()

Format this object in a locale-specific way.


toString

public String toString()