Asterisk-Java

org.asteriskjava.util
Class DateUtil

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

public class DateUtil
extends java.lang.Object

Utility class to obtain the current date and allows to override with a fixed value for unit testing. Includes some convenience methods for date conversion.

Client code is not supposed to use this class.

Version:
$Id: DateUtil.java 488 2006-07-15 11:46:52Z srt $
Author:
srt

Method Summary
static java.util.Date getDate()
          Returns the real current date or the date set with overrideCurrentDate().
static void overrideCurrentDate(java.util.Date currentDate)
          If set to a non null value uses the date given as current date on calls to getDate().
static java.util.Date parseDateTime(java.lang.String s)
          Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the default timezone.
static java.util.Date parseDateTime(java.lang.String s, java.util.TimeZone tz)
          Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the given timezone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

overrideCurrentDate

public static void overrideCurrentDate(java.util.Date currentDate)
If set to a non null value uses the date given as current date on calls to getDate(). Set to null to restore the normal behavior.

Parameters:
currentDate - the date to return on calls to getDate() or null to return the real current date.

getDate

public static java.util.Date getDate()
Returns the real current date or the date set with overrideCurrentDate().

Returns:
the real current date or the date set with overrideCurrentDate().

parseDateTime

public static java.util.Date parseDateTime(java.lang.String s)
Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the default timezone.

Parameters:
s - date string in the form of "yy-MM-dd HH:mm:ss"
Returns:
the corresponding Java date object

parseDateTime

public static java.util.Date parseDateTime(java.lang.String s,
                                           java.util.TimeZone tz)
Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the given timezone.

Parameters:
s - date string in the form of "yy-MM-dd HH:mm:ss"
tz - the timezone to use
Returns:
the corresponding Java date object

Asterisk-Java

Copyright © 2004-2007 Stefan Reuter. All Rights Reserved.