com.javaranch.common
Class GDate

java.lang.Object
  |
  +--com.javaranch.common.GDate
Direct Known Subclasses:
ADate

public class GDate
extends java.lang.Object

Gregorian Date, international format (YYYY/MM/DD).

These dates are stored as Year, Month and Day. Not very memory efficient, but good for converting to strings, or quickly extracting the day of the month.

See the complimentary class JDate for memory efficiency or doing date math.

This object uses the international YYYY/MM/DD format. See ADate for MM/DD/YYYY format.

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton

Constructor Summary
GDate()
          Create a Gregorian Date object with a default of today's date.
GDate(java.util.Date date)
           
GDate(GDate d)
          Create a Gregorian Date object from another Gregorian Date object (GDate or ADate).
GDate(int year, int month, int day)
          Create a Gregorian Date object with a specific date.
GDate(JDate j)
          Create a Gregorian Date object with a specific Julian date.
GDate(java.lang.String textDate)
          Create a Gregorian Date object with a loosely formatted text date.
GDate(java.util.TimeZone timeZone)
          Create a Gregorian Date object with a default of today's date.
 
Method Summary
 java.lang.Object clone()
          Get a copy of this object.
 boolean equals(java.lang.Object obj)
           
 int getDay()
          Return the day of the month (1..31).
 java.lang.String getFixedFormat()
          Such as "2000/05/01".
 java.lang.String getLongFormat()
          Returns a date formatted like "September 22, 1999".
 int getMonth()
           
 java.lang.String getMonthString()
          Get the full month name.
static java.lang.String getMonthString(int month)
          Convert a number 1 through 12 to a String "January" through "December".
 java.lang.String getShortFormat()
          Deprecated.  
 java.sql.Timestamp getTimestamp()
           
 java.sql.Timestamp getTimestamp(java.util.TimeZone timeZone)
           
static GDate getToday(java.util.TimeZone timeZone)
           
 int getYear()
           
 void set(java.lang.String textDate)
          Force the date based on the contents of a string.
 void setDay(int day)
          Expects values 1..31 although invalid values are accepted.
 void setMonth(int month)
          Expects values 1..12 although invalid values are accepted.
 void setToToday(java.util.TimeZone timeZone)
          Set this object to reflect today's date.
 void setYear(int year)
           
 java.lang.String toString()
          Returns a date formatted like "2000/7/24".
static java.lang.String toString(GDate g)
          Returns a date formatted like "2000/7/24".
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GDate

public GDate()
Create a Gregorian Date object with a default of today's date.


GDate

public GDate(java.util.TimeZone timeZone)
Create a Gregorian Date object with a default of today's date.


GDate

public GDate(int year,
             int month,
             int day)
Create a Gregorian Date object with a specific date.


GDate

public GDate(JDate j)
Create a Gregorian Date object with a specific Julian date.


GDate

public GDate(GDate d)
Create a Gregorian Date object from another Gregorian Date object (GDate or ADate).


GDate

public GDate(java.lang.String textDate)
Create a Gregorian Date object with a loosely formatted text date.

The general format is YYYY/MM/DD.

Any type of delimiter can be used (slash, hyphen, space, etc.). The month and date does not have to be two digits in length. The year does not have to be four digits in length, although "98" will be interpretted as 0098, not 1998 or 2098.

Invalid dates are accepted.

If you leave out the day of the month, the first is assumed.

If you leave out the month, January is assumed.


GDate

public GDate(java.util.Date date)
Method Detail

set

public void set(java.lang.String textDate)
Force the date based on the contents of a string.

The general format is YYYY/MM/DD.

Any type of delimiter can be used (slash, hyphen, space, etc.). The month and date does not have to be two digits in length. The year does not have to be four digits in length, although "98" will be interpretted as 0098, not 1998 or 2098.

Invalid dates are accepted.

If you leave out the day of the month, the first is assumed.

If you leave out the month, January is assumed.


setToToday

public void setToToday(java.util.TimeZone timeZone)
Set this object to reflect today's date.


setYear

public void setYear(int year)

setMonth

public void setMonth(int month)
Expects values 1..12 although invalid values are accepted.


setDay

public void setDay(int day)
Expects values 1..31 although invalid values are accepted.


getYear

public int getYear()

getMonth

public int getMonth()

getMonthString

public static java.lang.String getMonthString(int month)
Convert a number 1 through 12 to a String "January" through "December".

Passing in values outside of the 1 through 12 range will return an empty string.


getMonthString

public java.lang.String getMonthString()
Get the full month name.

If the current month is outside of the 1 through 12 range, an empty string will be returned.

Month names will be capitalized properly. e.g. "January".


getDay

public int getDay()
Return the day of the month (1..31).


getShortFormat

public java.lang.String getShortFormat()
Deprecated.  

Such as "05-01-2000".


getFixedFormat

public java.lang.String getFixedFormat()
Such as "2000/05/01".


toString

public static java.lang.String toString(GDate g)
Returns a date formatted like "2000/7/24".


toString

public java.lang.String toString()
Returns a date formatted like "2000/7/24".

Overrides:
toString in class java.lang.Object

getLongFormat

public java.lang.String getLongFormat()
Returns a date formatted like "September 22, 1999".


getTimestamp

public java.sql.Timestamp getTimestamp()

getTimestamp

public java.sql.Timestamp getTimestamp(java.util.TimeZone timeZone)

clone

public java.lang.Object clone()
Get a copy of this object.

Overrides:
clone in class java.lang.Object

getToday

public static GDate getToday(java.util.TimeZone timeZone)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


Copyright ©2004 Paul Wheaton All Rights Reserved