org.pf.util
Class DateUtil

java.lang.Object
  extended by org.pf.util.DateUtil

public class DateUtil
extends java.lang.Object

This class is intended to provide convenience methods around the java.util.Date class. It is not always necessary to fiddle around with the awkward GregorianCalendar and not everybody wants to use the deprecated methods of java.util.Date.

Be aware that this class always treats months 1-based NOT zero-based. That is: 1=January, 2=February, 3=March, ..., 12=December

Version:
2.0
Author:
Manfred Duchrow

Field Summary
static java.text.SimpleDateFormat DF_GERMAN_DATE
           
static java.text.SimpleDateFormat DF_GERMAN_DATE_TIME
           
static java.text.SimpleDateFormat DF_UK_DATE
           
static java.text.SimpleDateFormat DF_US_DATE
           
static java.util.TimeZone TIMEZONE_GERMANY
           
static java.util.TimeZone TIMEZONE_GMT
           
static java.util.TimeZone TIMEZONE_UTC
           
 
Method Summary
 java.util.Calendar asCalendar(java.util.Date date)
          Returns the given date as Calendar in the current machines time zone.
 java.util.Calendar asCalendar(java.util.TimeZone timezone, java.util.Date date)
          Returns the given date as Calendar in the specified time zone.
 java.util.Calendar asGMTCalendar(java.util.Date date)
          Returns the given date as Calendar in the GMT time zone.
 java.lang.String convertDateIntoZuluTime(java.util.Date date)
          Converts the given date into the so-called zulu time.
 java.util.Date convertZuluTimeIntoDate(java.lang.String str)
          Converts the given string that must be formatted as so-called zulu-time to a Date object.
static DateUtil current()
          Returns the only instance this class supports (design pattern "Singleton")
 java.util.Date newDate(int year, int month, int day)
          Returns a Date object representing the given parameters.
 java.util.Date newDate(int year, int month, int day, int hour, int minute)
          Returns a Date object representing the given parameters.
 java.util.Date newDate(int year, int month, int day, int hour, int minute, int second)
          Returns a Date object representing the given parameters.
 java.util.Date newDate(java.util.TimeZone timezone, int year, int month, int day)
          Returns a Date object representing the given parameters.
 java.util.Date newDate(java.util.TimeZone timezone, int year, int month, int day, int hour, int minute, int second)
          Returns a Date object representing the given parameters.
 java.util.Date newGMTDate(int year, int month, int day, int hour, int minute, int second)
          Returns a Date object in time zone GMT representing the given parameters.
 java.util.Date today()
          Returns the current date
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEZONE_UTC

public static final java.util.TimeZone TIMEZONE_UTC

TIMEZONE_GMT

public static final java.util.TimeZone TIMEZONE_GMT

TIMEZONE_GERMANY

public static final java.util.TimeZone TIMEZONE_GERMANY

DF_GERMAN_DATE

public static final java.text.SimpleDateFormat DF_GERMAN_DATE

DF_UK_DATE

public static final java.text.SimpleDateFormat DF_UK_DATE

DF_US_DATE

public static final java.text.SimpleDateFormat DF_US_DATE

DF_GERMAN_DATE_TIME

public static final java.text.SimpleDateFormat DF_GERMAN_DATE_TIME
Method Detail

current

public static DateUtil current()
Returns the only instance this class supports (design pattern "Singleton")


newDate

public java.util.Date newDate(int year,
                              int month,
                              int day)
Returns a Date object representing the given parameters.

Parameters:
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create

newDate

public java.util.Date newDate(java.util.TimeZone timezone,
                              int year,
                              int month,
                              int day)
Returns a Date object representing the given parameters.

Parameters:
timezone - The time zone to which the other parameters are related
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create

newDate

public java.util.Date newDate(int year,
                              int month,
                              int day,
                              int hour,
                              int minute)
Returns a Date object representing the given parameters.

Parameters:
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create
hour - The hours (0-23)
minute - The minutes (0-59)

newDate

public java.util.Date newDate(int year,
                              int month,
                              int day,
                              int hour,
                              int minute,
                              int second)
Returns a Date object representing the given parameters.

Parameters:
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create
hour - The hours (0-23)
minute - The minutes (0-59)
second - The seconds (0-59)

newGMTDate

public java.util.Date newGMTDate(int year,
                                 int month,
                                 int day,
                                 int hour,
                                 int minute,
                                 int second)
Returns a Date object in time zone GMT representing the given parameters.

Parameters:
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create
hour - The hours (0-23)
minute - The minutes (0-59)
second - The seconds (0-59)

newDate

public java.util.Date newDate(java.util.TimeZone timezone,
                              int year,
                              int month,
                              int day,
                              int hour,
                              int minute,
                              int second)
Returns a Date object representing the given parameters.

Parameters:
timezone - The time zone to which the other parameters are related
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create
hour - The hours (0-23)
minute - The minutes (0-59)
second - The seconds (0-59)

today

public java.util.Date today()
Returns the current date


asCalendar

public java.util.Calendar asCalendar(java.util.Date date)
Returns the given date as Calendar in the current machines time zone.


asCalendar

public java.util.Calendar asCalendar(java.util.TimeZone timezone,
                                     java.util.Date date)
Returns the given date as Calendar in the specified time zone.


asGMTCalendar

public java.util.Calendar asGMTCalendar(java.util.Date date)
Returns the given date as Calendar in the GMT time zone.


convertDateIntoZuluTime

public java.lang.String convertDateIntoZuluTime(java.util.Date date)
Converts the given date into the so-called zulu time. That is: "yyyy-MM-dd'T'HH:mm:ssZ"


convertZuluTimeIntoDate

public java.util.Date convertZuluTimeIntoDate(java.lang.String str)
                                       throws java.text.ParseException
Converts the given string that must be formatted as so-called zulu-time to a Date object.

Throws:
java.text.ParseException