org.brains2b.util
Class DateHelper
java.lang.Object
org.brains2b.util.DateHelper
- public class DateHelper
- extends java.lang.Object
A function library giving some extra help dealing with dates.
- Version:
- 0.13 [30-06-2007]
- Author:
- dennis@brains2b.nl
Method Summary |
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
This toDate function is basically a rule based system recognizing a Date
in the following patterns:
a six digit String is interpreted as ddMMyy
a String with a non character separator is interpreted as
day-month-year
day can be either 1 or 2 digits, with or without a
leading 0
month can be either 1 or 2 digits, with or without a
leading 0, a String representing the long name or a short name of the
month. |
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 |
DateHelper
public DateHelper()
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
This toDate function is basically a rule based system recognizing a Date
in the following patterns:
- a six digit String is interpreted as
ddMMyy
- a String with a non character separator is interpreted as
day-month-year
day
can be either 1 or 2 digits, with or without a
leading 0
month
can be either 1 or 2 digits, with or without a
leading 0, a String representing the long name or a short name of the
month. The name of the month must be in the same language at which the VM
it is operating is running in Locale.getDefault() is used to determine
this.
year
can be 1 or 2 digits, with or without a leading
0. This is interpreted as a year without a century, so the current
century is added. It can also be four digits and will then be intrepeted
as year including a century.
- Parameters:
txt
- String that should be intrepeted as Date
- Returns:
- Date, the result of transforming txt into a new Date
- Throws:
NumberFormatException,
- thrown if at an expected number was not found at the Expected
position.
java.lang.NumberFormatException
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)