UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.util
Class DateLib

java.lang.Object
  |
  +--edu.berkeley.guir.lib.util.DateLib

public final class DateLib
extends Object

Formats Java Date object as ISO date (ISO8601). Format is YYYYMMDDTHHMMSS. For example,

 19960329T083000Z
 19960401T235959
 
This needs to be fixed so that illegal dates will not be allowed, and that leap years will be calculated correctly. This is because the Calendar class does not check bounds correctly (e.g. February 29 becomes March 1). Go figure.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Nov 27 1997, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.2
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Method Summary
static int compareDate(Date date1, Date date2)
          Compare two dates.
static int compareDate(Date date1, String strDate2)
          See the other compareDate() method for details.
static int compareDate(String strDate1, Date date2)
          See the other compareDate() method for details.
static int compareDate(String strDate1, String strDate2)
          See the other compareDate() method for details.
static String DateToISO(Date date)
          Convert a Java Date object to an ISO date string.
static String getCurrentISODate()
          Get the current date and time in ISO format.
static Date ISOToDate(String str)
          Convert an ISO date string to a Java Date object.
static boolean isValidISODate(String str)
          See if the specified String is a valid date.
static void main(String[] argv)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCurrentISODate

public static String getCurrentISODate()
Get the current date and time in ISO format.
Returns:
a String containing the current date and time.

compareDate

public static int compareDate(Date date1,
                              Date date2)
Compare two dates.
 if date1 lthan date2 = -1
 if date1   =   date2 = 0
 if date1 gthan date2 = 1
 
Parameters:
date1 - is a Java Date object.
date2 - is a Java Date object.

compareDate

public static int compareDate(Date date1,
                              String strDate2)
See the other compareDate() method for details.
Parameters:
date1 - is a Java Date object.
strDate2 - is an ISO format date.

compareDate

public static int compareDate(String strDate1,
                              Date date2)
See the other compareDate() method for details.
Parameters:
strDate1 - is an ISO format date.
date2 - is a Java Date object.

compareDate

public static int compareDate(String strDate1,
                              String strDate2)
See the other compareDate() method for details.
Parameters:
strDate1 - is an ISO format date.
strDate2 - is an ISO format date.

DateToISO

public static String DateToISO(Date date)
Convert a Java Date object to an ISO date string.

isValidISODate

public static boolean isValidISODate(String str)
See if the specified String is a valid date.

ISOToDate

public static Date ISOToDate(String str)
Convert an ISO date string to a Java Date object. String format expected is YYYYMMDDTHHMMSS[Z].

main

public static void main(String[] argv)

Copyright Information