public class DateUtil
extends java.lang.Object
Be aware that this class always treats months 1-based NOT zero-based. That is: 1=January, 2=February, 3=March, ..., 12=December
All date representations of this class are by default based on Locale.getDefault(),
but this can be changed via setDefaultLocale(Locale)
.
Modifier and Type | Field and Description |
---|---|
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.lang.String |
GERMAN_DATE_FORMAT |
static java.lang.String |
RFC_1123_DATE_FORMAT
The date format according to RFC-1123.
|
static java.lang.String |
SORT_DATE_FORMAT |
static java.util.TimeZone |
TIMEZONE_GERMANY |
static java.util.TimeZone |
TIMEZONE_GMT |
static java.util.TimeZone |
TIMEZONE_UTC |
static java.lang.String |
UK_DATE_FORMAT |
static java.lang.String |
US_DATE_FORMAT |
Modifier | Constructor and Description |
---|---|
protected |
DateUtil()
Initialize the new instance with default values.
|
Modifier and Type | Method and Description |
---|---|
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.lang.String |
formatRFC1123(java.util.Date date)
Formats the given date according to RFC-1123 which is also used by HTTP/1.1
(see specification section 3.3.1).
|
java.lang.String |
getDateFormatForLocale(java.util.Locale locale)
Returns the date format (only dd MM yyyy) for the given locale.
|
java.lang.String |
getDefaultDateFormat()
Returns the date format for the current default locale of this singleton.
|
java.util.Locale |
getDefaultLocale()
Returns the default locale used inside all methods of this singleton.
|
protected java.text.SimpleDateFormat |
getRFC1123Formatter() |
java.util.Calendar |
newCalendar(int year,
int month,
int day,
int hour,
int minute,
int second)
Returns a Date object representing the given parameters.
|
java.util.Calendar |
newCalendar(java.util.TimeZone timezone,
int year,
int month,
int day,
int hour,
int minute,
int second)
Returns a Calendar object representing the given parameters.
|
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 |
parseDateRFC1123(java.lang.String value)
Parses the given string assuming its format complies with RFC-1123.
|
void |
setDefaultLocale(java.util.Locale locale)
Sets the default locale for usage inside all methods of this singleton.
|
java.util.Date |
today()
Returns the current date
|
public static final java.util.TimeZone TIMEZONE_UTC
public static final java.util.TimeZone TIMEZONE_GMT
public static final java.util.TimeZone TIMEZONE_GERMANY
public static final java.lang.String SORT_DATE_FORMAT
public static final java.lang.String GERMAN_DATE_FORMAT
public static final java.lang.String UK_DATE_FORMAT
public static final java.lang.String US_DATE_FORMAT
public static final java.text.SimpleDateFormat DF_GERMAN_DATE
public static final java.text.SimpleDateFormat DF_UK_DATE
public static final java.text.SimpleDateFormat DF_US_DATE
public static final java.text.SimpleDateFormat DF_GERMAN_DATE_TIME
public static final java.lang.String RFC_1123_DATE_FORMAT
public static DateUtil current()
public java.util.Date newDate(int year, int month, int day)
year
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createpublic java.util.Date newDate(java.util.TimeZone timezone, int year, int month, int day)
timezone
- The time zone to which the other parameters are relatedyear
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createpublic java.util.Date newDate(int year, int month, int day, int hour, int minute)
year
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)public java.util.Date newDate(int year, int month, int day, int hour, int minute, int second)
year
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)second
- The seconds (0-59)public java.util.Calendar newCalendar(int year, int month, int day, int hour, int minute, int second)
year
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)second
- The seconds (0-59)public java.util.Date newGMTDate(int year, int month, int day, int hour, int minute, int second)
year
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)second
- The seconds (0-59)public java.util.Date newDate(java.util.TimeZone timezone, int year, int month, int day, int hour, int minute, int second)
timezone
- The time zone to which the other parameters are relatedyear
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)second
- The seconds (0-59)public java.util.Calendar newCalendar(java.util.TimeZone timezone, int year, int month, int day, int hour, int minute, int second)
timezone
- The time zone to which the other parameters are relatedyear
- The year of the date to createmonth
- The month of the date to create (1-based, 1=January)day
- The day of the date to createhour
- The hours (0-23)minute
- The minutes (0-59)second
- The seconds (0-59)public java.util.Date today()
public java.util.Calendar asCalendar(java.util.Date date)
public java.util.Calendar asCalendar(java.util.TimeZone timezone, java.util.Date date)
public java.util.Calendar asGMTCalendar(java.util.Date date)
public java.lang.String convertDateIntoZuluTime(java.util.Date date)
public java.util.Date convertZuluTimeIntoDate(java.lang.String str) throws java.text.ParseException
java.text.ParseException
public java.lang.String formatRFC1123(java.util.Date date)
Example: "Sun, 06 Nov 1994 08:49:37 GMT" ; RFC-1123
date
- The date to format (if null, null will be returned).public java.util.Date parseDateRFC1123(java.lang.String value)
value
- The string to be parsed (if null, null will be returned).java.lang.IllegalArgumentException
- If the string cannot be parsed to a date.public java.util.Locale getDefaultLocale()
public void setDefaultLocale(java.util.Locale locale)
public java.lang.String getDefaultDateFormat()
getDefaultLocale()
,
setDefaultLocale(Locale)
public java.lang.String getDateFormatForLocale(java.util.Locale locale)
protected java.text.SimpleDateFormat getRFC1123Formatter()