org.brains2b.util
Class DateHelper

java.lang.Object
  extended byorg.brains2b.util.DateHelper

public class DateHelper
extends java.lang.Object

A function library giving some extra help dealing with dates.

Version:
$Revision: 1.13 $ $Date: 2009/09/15 08:09:58 $
Author:
dennis@brains2b.nl

Constructor Summary
DateHelper()
           
 
Method Summary
static int betweenDate(java.util.Calendar c1, java.util.Calendar c2, int field, boolean round)
          calculate the difference between two Calendars in intervals defined by field.
static int betweenDate(java.util.Date d1, java.util.Date d2, int field, boolean round)
          calculate the difference between two Dates in intervals defined by field.
static java.lang.String fromDate(java.util.Date dt)
          gets a date formatted as String with pattern "dd-MMM-yyyy"
static java.lang.String isoFromDate(java.util.Date d)
           
static java.lang.String isoFromDate(java.util.Date d, boolean includeTime)
           
static java.util.Date isoToDate(java.lang.String s)
           
static java.util.Date toDate(java.lang.String txt)
          returns a Date from a String representing a Date
static java.util.Date toDate(java.lang.String txt, java.util.Locale locale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateHelper

public DateHelper()
Method Detail

fromDate

public static final java.lang.String fromDate(java.util.Date dt)
gets a date formatted as String with pattern "dd-MMM-yyyy"

Parameters:
dt - java.util.Date
Returns:
String the formatted date, or null if Date was not given.

toDate

public static final java.util.Date toDate(java.lang.String txt)
                                   throws java.lang.NumberFormatException
returns a Date from a String representing a Date


toDate

public static final java.util.Date toDate(java.lang.String txt,
                                          java.util.Locale locale)
                                   throws java.lang.NumberFormatException
Throws:
java.lang.NumberFormatException

isoFromDate

public static final java.lang.String isoFromDate(java.util.Date d,
                                                 boolean includeTime)

isoFromDate

public static final java.lang.String isoFromDate(java.util.Date d)

isoToDate

public static final java.util.Date isoToDate(java.lang.String s)

betweenDate

public static final int betweenDate(java.util.Date d1,
                                    java.util.Date d2,
                                    int field,
                                    boolean round)
calculate the difference between two Dates in intervals defined by field.

The compare of the calendars follows normal conventions, so if c1 > c2 you will get a negative number. If rounding is on the level below is measured and normal rounding rules apply.

The field value should be one of Calendar.YEAR,Calendar.MONTH,Calendar.DATE

Parameters:
d1 - Date one (required)
d2 - Date two (required)
field - int, should be in (Calendar.YEAR|Calendar.MONTH|Calendar.DATE)
round - boolean, true if the should difference be rounded according to the normal rounding rules.False will floor the value
Returns:
int, the difference between the Dates in the defined measure
Since:
1.04.1

betweenDate

public static final int betweenDate(java.util.Calendar c1,
                                    java.util.Calendar c2,
                                    int field,
                                    boolean round)
calculate the difference between two Calendars in intervals defined by field.

The compare of the calendars follows normal conventions, so if c1 > c2 you will get a negative number. If rounding is on the level below is measured and normal rounding rules apply.

The field value should be one of Calendar.YEAR,Calendar.MONTH,Calendar.DATE

Parameters:
c1 - Calendar one (required)
c2 - Calendar two (required)
field - int, should be in (Calendar.YEAR|Calendar.MONTH|Calendar.DATE)
round - boolean, true if the should difference be rounded according to the normal rounding rules.False will floor the value
Returns:
int, the difference between the Calendars in the defined measure
Since:
1.04.1