com.partnersoft.data
Class DateAndTime

java.lang.Object
  extended by com.partnersoft.data.DateAndTime
All Implemented Interfaces:
Immutable, java.lang.Comparable

public class DateAndTime
extends java.lang.Object
implements java.lang.Comparable, Immutable

A representation of a date and time as day, month, year, and time of day.

This class is designed as a simpler alternative to Date, which has a number of problems and inconveniences.

Copyright 1997-2006 Partner Software, Inc.

Author:
Paul Reavis
See Also:
Date, Time

Field Summary
static java.text.DateFormat format
           
 
Constructor Summary
DateAndTime()
          Creates a new DateAndTime corresponding to the current date and time.
DateAndTime(java.util.Date dateAndTime)
          Creates a new DateAndTime from the given java.util.Date object.
DateAndTime(long millis)
          Creates a new DateAndTime for the given milliseconds since the epoc (same as java.util.Date convention).
DateAndTime(java.lang.String dateAndTimeString)
          Creates a new DateAndTime from the given String.
DateAndTime(java.sql.Timestamp dateAndTime)
          Creates a new DateAndTime from the given java.sql.Timestamp object.
 
Method Summary
 int compareTo(java.lang.Object nother)
           
 boolean equals(java.lang.Object nother)
          Casts passed object to DateAndTime and compares to this object.
 java.lang.String format(java.lang.String formatString)
          Format this DateAndTime as a String using the usual Java SimpleDateFormat syntax.
 Date getDate()
          Returns the date portion of this DateAndTime.
 long getMillis()
          Returns the internal millisecond representation (same format java.util.Date uses).
 Time getTime()
          Returns the time portion of this DateAndTime.
 java.sql.Date toJavaSqlDate()
           
 java.sql.Timestamp toJavaSqlTimestamp()
           
 java.util.Date toJavaUtilDate()
          A normal Date object representing this DateAndTime.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

format

public static final java.text.DateFormat format
Constructor Detail

DateAndTime

public DateAndTime()
Creates a new DateAndTime corresponding to the current date and time.


DateAndTime

public DateAndTime(long millis)
Creates a new DateAndTime for the given milliseconds since the epoc (same as java.util.Date convention).


DateAndTime

public DateAndTime(java.lang.String dateAndTimeString)
Creates a new DateAndTime from the given String.

Parameters:
dateAndTimeString -
Throws:
java.lang.IllegalArgumentException - if it can't parse the input.

DateAndTime

public DateAndTime(java.util.Date dateAndTime)
Creates a new DateAndTime from the given java.util.Date object.

Parameters:
dateAndTime - a java.util.Date representing the desired date and time.

DateAndTime

public DateAndTime(java.sql.Timestamp dateAndTime)
Creates a new DateAndTime from the given java.sql.Timestamp object.

Parameters:
dateAndTime - a java.sql.Timestamp representing the desired date and time.
Method Detail

toJavaUtilDate

public java.util.Date toJavaUtilDate()
A normal Date object representing this DateAndTime.


getDate

public Date getDate()
Returns the date portion of this DateAndTime.


getTime

public Time getTime()
Returns the time portion of this DateAndTime.


getMillis

public long getMillis()
Returns the internal millisecond representation (same format java.util.Date uses).


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Casts passed object to DateAndTime and compares to this object.

Overrides:
equals in class java.lang.Object
Returns:
true if both object's millis fields match, false if fields don't match, object is not a DateAndTime, or object is null.

compareTo

public int compareTo(java.lang.Object nother)
Specified by:
compareTo in interface java.lang.Comparable

format

public java.lang.String format(java.lang.String formatString)
Format this DateAndTime as a String using the usual Java SimpleDateFormat syntax.

Parameters:
formatString -
Returns:

toJavaSqlTimestamp

public java.sql.Timestamp toJavaSqlTimestamp()

toJavaSqlDate

public java.sql.Date toJavaSqlDate()