de.bb.util
Class DateFormat

java.lang.Object
  extended by de.bb.util.DateFormat

public class DateFormat
extends java.lang.Object

A collection of high speed date conversion functions. If you ever measured the really low performance of the JDK DateFormat classes, you understand its purpose instantly. The most needed date/time formatting functions plus the String parsing functions are supplied.


Field Summary
static int FRIDAY
          constant value for Friday.
static int MONDAY
          constant value for Monday.
static int SATURDAY
          constant value for Saturday.
static int SUNDAY
          constant value for Sunday.
static int THURSDAY
          constant value for Thursday.
static long TIME_PER_DAY
          millis per day.
static int TUESDAY
          constant value for Tuesday.
static int WEDNESDAY
          constant value for Wednesday.
 
Constructor Summary
DateFormat(java.lang.String format)
          This constructor deales with various date formats.
DateFormat(java.lang.String format, int tz)
          Constructor DateFormat.
 
Method Summary
static long addMonths(long t, int months)
          Add the count of months to the time value.
static byte[] ba_dd_MMM_yyyy_HH_mm_ss_zzzz(long l)
          Return a byte array for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.
static byte[] ba_EEE__dd_MMM_yyyy_HH_mm_ss_GMT(long l)
          Return a byte array for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.
static int[] calc(long l)
          Creates an array of int[8] with all time elements.
static int[] calc(long l, int timeZone)
          Creates an array of int[8] with all time elements.
static java.lang.String dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz(long l)
          Return a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss GMT+zz:zz.
static java.lang.String dd_MMM_yyyy_HH_mm_ss_zzzz(long l)
          Return a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.
static java.lang.String ddMMyyyy(long l)
          Return a String for the given date (long) in format ddMMyyyy.
static java.lang.String ddMMyyyyHHmmss(long l)
          Return a String for the given date (long) in format ddMMyyyyHHmmss.
static long eastern(int year)
          Calculates the easter day for a given year > 1970.
static java.lang.String EEE__dd_MMM_yyyy_HH_mm_ss__zzzz(long l)
          Return a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss +zzzz.
static java.lang.String EEE__dd_MMM_yyyy_HH_mm_ss_GMT(long l)
          Return a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.
static long firstOfDay(long t)
          Returns a time value for the specified day at 00:00:00.000 with current time zone.
static long firstOfMonth(long date)
          Returns the value for the first day in date's month.
static long firstOfWeek(long time)
          get the first day of the corresponding week.
static long firstOfYear(long date)
          Returns the value for the first day in date's year.
 java.lang.String format(long time)
          Returns the formatted String using the format String specifed at the constructor.
static int getDayOfMonth(long date)
          Method getDayOfMonth.
 java.lang.String getMask()
          Returns the current fill bytes.
static int getMonth(long t)
          the month the given date.
static int getWeek(long time)
          Method getWeek returns the week number for the supplied date.
static int getWeekDay(long time)
          Returns the weekday, from 1-7 where 1 = Sunday.
static int getYear(long t)
          the year for the given time value.
static void initTimeZone()
          Used to read the time tone from System properties.
static long nextMonth(long date)
          Returns the value for date plus 1 month.
static long nextWeek(long date)
          Returns the value for date plus 1 week.
static long parse_dd_MM_yyyy_HH_mm_ss_GMT_zz_zz(java.lang.String date)
          Return a long for the given date date in format dd MM yyyy HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
static long parse_dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz(java.lang.String date)
          Return a long for the given date date in format dd MMM yyyy HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
static long parse_yyyy_MM_dd_HH_mm_ss_GMT_zz_zz(java.lang.String date)
          Return a long for the given date date in format yyyy MM dd HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
 long parse(java.lang.String string)
          Parses the date string with the current formatter.
static long toLong(int[] n)
          calculates the long value from the int array - retrieved by calc[].
static java.lang.String yyyyMMdd(long l)
          Return a String for the given date (long) in format yyyyMMdd.
static java.lang.String yyyyMMddHH(long l)
          Return a String for the given date (long) in format yyyyMMddHH.
static java.lang.String yyyyMMddHHmmss(long l)
          Return a String for the given date (long) in format yyyyMMddHHmmss.
static java.lang.String yyyyMMddHHmmssSSS(long l)
          Return a String for the given date (long) in format yyyyMMddHHmmssSSS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUNDAY

public static final int SUNDAY
constant value for Sunday.

See Also:
Constant Field Values

MONDAY

public static final int MONDAY
constant value for Monday.

See Also:
Constant Field Values

TUESDAY

public static final int TUESDAY
constant value for Tuesday.

See Also:
Constant Field Values

WEDNESDAY

public static final int WEDNESDAY
constant value for Wednesday.

See Also:
Constant Field Values

THURSDAY

public static final int THURSDAY
constant value for Thursday.

See Also:
Constant Field Values

FRIDAY

public static final int FRIDAY
constant value for Friday.

See Also:
Constant Field Values

SATURDAY

public static final int SATURDAY
constant value for Saturday.

See Also:
Constant Field Values

TIME_PER_DAY

public static final long TIME_PER_DAY
millis per day.

See Also:
Constant Field Values
Constructor Detail

DateFormat

public DateFormat(java.lang.String format)
This constructor deales with various date formats. Supported abbreviations are: if 2 or less characters are used, the short form is used (if any exist). Otherwise leading zeros are inserted to reach the defined amount.

Parameters:
format - the format string

DateFormat

public DateFormat(java.lang.String format,
                  int tz)
Constructor DateFormat.

Parameters:
format - the format string
tz - timezone offset in seconds
See Also:
DateFormat(String)
Method Detail

getMask

public java.lang.String getMask()
Returns the current fill bytes. Means all date/time digits are replaces by spaces.

Returns:
Returns the current fill bytes. Means all date/time digits are replaces by spaces.

format

public java.lang.String format(long time)
Returns the formatted String using the format String specifed at the constructor. Important to know that this is much faster than the java.util.DateFormat, it is still 3 times slower than the explicit (hard coded) static format functions.

Parameters:
time - GMT time in milli seconds.
Returns:
Returns the formatted String using the format String specifed at the constructor.

ba_dd_MMM_yyyy_HH_mm_ss_zzzz

public static byte[] ba_dd_MMM_yyyy_HH_mm_ss_zzzz(long l)
Return a byte array for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.
 e.g. 01/Jan/1970:00:00:01 +02:00
 
.

Parameters:
l - a long representing a date value
Returns:
a byte array for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.

dd_MMM_yyyy_HH_mm_ss_zzzz

public static java.lang.String dd_MMM_yyyy_HH_mm_ss_zzzz(long l)
Return a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.
 e.g. 01/Jan/1970:00:00:01 +02:00
 
.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss +zz:zz.

dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz

public static java.lang.String dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz(long l)
Return a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss GMT+zz:zz.
 e.g. 01/Jan/1970:00:00:01 GMT+02:00
 
.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format dd/MMM/yyyy:HH:mm:ss GMT+zz:zz.

EEE__dd_MMM_yyyy_HH_mm_ss__zzzz

public static java.lang.String EEE__dd_MMM_yyyy_HH_mm_ss__zzzz(long l)
Return a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss +zzzz.
 e.g. Thu, 01 Jan 1970 00:00:01 +0200
 
.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss +zzzz.

ba_EEE__dd_MMM_yyyy_HH_mm_ss_GMT

public static byte[] ba_EEE__dd_MMM_yyyy_HH_mm_ss_GMT(long l)
Return a byte array for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.
 e.g. Mon, 01 Jan 1970 00:00:01 GMT
 
.

Parameters:
l - a long representing a date value
Returns:
a byteA array for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.

EEE__dd_MMM_yyyy_HH_mm_ss_GMT

public static java.lang.String EEE__dd_MMM_yyyy_HH_mm_ss_GMT(long l)
Return a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.
 e.g. Mon, 01 Jan 1970 00:00:01 GMT
 
.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format EEE, dd MMM yyyy HH:mm:ss GMT.

yyyyMMddHHmmss

public static java.lang.String yyyyMMddHHmmss(long l)
Return a String for the given date (long) in format yyyyMMddHHmmss.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format yyyyMMddHHmmss.

yyyyMMddHHmmssSSS

public static java.lang.String yyyyMMddHHmmssSSS(long l)
Return a String for the given date (long) in format yyyyMMddHHmmssSSS.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format yyyyMMddHHmmssSSS.

ddMMyyyyHHmmss

public static java.lang.String ddMMyyyyHHmmss(long l)
Return a String for the given date (long) in format ddMMyyyyHHmmss.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format ddMMyyyyHHmmss.

yyyyMMddHH

public static java.lang.String yyyyMMddHH(long l)
Return a String for the given date (long) in format yyyyMMddHH.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format yyyyMMddHH.

yyyyMMdd

public static java.lang.String yyyyMMdd(long l)
Return a String for the given date (long) in format yyyyMMdd.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format yyyyMMdd.

ddMMyyyy

public static java.lang.String ddMMyyyy(long l)
Return a String for the given date (long) in format ddMMyyyy.

Parameters:
l - a long representing a date value
Returns:
a String for the given date (long) in format ddMMyyyy.

calc

public static int[] calc(long l)
Creates an array of int[8] with all time elements. .

Parameters:
l - a long representing a date value
Returns:
a new allocated array containing the calculated values

calc

public static int[] calc(long l,
                         int timeZone)
Creates an array of int[8] with all time elements. .

Parameters:
l - a long representing a date value
timeZone - an explicit time zone
Returns:
a new allocated array containing the calculated values

toLong

public static long toLong(int[] n)
calculates the long value from the int array - retrieved by calc[].

Parameters:
n - the int array as calculated by calc.
Returns:
the long value.

parse_dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz

public static long parse_dd_MMM_yyyy_HH_mm_ss_GMT_zz_zz(java.lang.String date)
Return a long for the given date date in format dd MMM yyyy HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
 e.g. 01/Jan/1970:00:00:01 GMT+02:00
 e.g. 01/Jan/1970:00:00:01
 e.g. 01/Jan/1970
 e.g. 01Jan                    1970   00::::::00::::::01  GMT    + 02 ---- 00
 
the value of delimiters is ignored!

Parameters:
date - a date value
Returns:
a long for the given date date in format dd MMM yyyy HH mm ss +zz zz

parse_dd_MM_yyyy_HH_mm_ss_GMT_zz_zz

public static long parse_dd_MM_yyyy_HH_mm_ss_GMT_zz_zz(java.lang.String date)
Return a long for the given date date in format dd MM yyyy HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
 e.g. 01/01/1970:00:00:01 GMT+02:00
 e.g. 01/01/1970:00:00:01
 e.g. 01/01/1970
 e.g. 0101                    1970   00::::::00::::::01  GTM    + 02 ---- 00
 
the value of delimiters is ignored!

Parameters:
date - a date value
Returns:
a long for the given date date in format dd MMM yyyy HH mm ss +zz zz

parse_yyyy_MM_dd_HH_mm_ss_GMT_zz_zz

public static long parse_yyyy_MM_dd_HH_mm_ss_GMT_zz_zz(java.lang.String date)
Return a long for the given date date in format yyyy MM dd HH mm ss +zz zz also values without timezone or without HH mm ss are parsed!
 e.g. 1970/01/01:00:00:01 GMT+02:00
 e.g. 1970/01/01:00:00:01
 e.g. 1970/01/01
 e.g. 19700101123000
 e.g. 1970 0101  00::::::00::::::01  GTM    + 02 ---- 00
 
the value of delimiters is ignored!

Parameters:
date - a date value
Returns:
a long for the given date date in format dd MMM yyyy HH mm ss +zz zz

eastern

public static long eastern(int year)
Calculates the easter day for a given year > 1970.

Parameters:
year - some year
Returns:
a time value for the easter day within that year in milli seconds since 01.01.1970

initTimeZone

public static void initTimeZone()
Used to read the time tone from System properties.


firstOfWeek

public static long firstOfWeek(long time)
get the first day of the corresponding week.

Parameters:
time - the time value
Returns:
long time value for the first day.

nextWeek

public static long nextWeek(long date)
Returns the value for date plus 1 week.

Parameters:
date - a GMT time in milli seconds.
Returns:
the value for date plus 1 week.

nextMonth

public static long nextMonth(long date)
Returns the value for date plus 1 month. If same day does not exist the last possible day is used.

Parameters:
date - a GMT time in milli seconds
Returns:
the value for date plus 1 month.

addMonths

public static long addMonths(long t,
                             int months)
Add the count of months to the time value.

Parameters:
t - a time value
months - the count of months to add
Returns:
the new time value.

firstOfMonth

public static long firstOfMonth(long date)
Returns the value for the first day in date's month.

Parameters:
date - a time in milli seconds
Returns:
the value for the first day in date's month.

firstOfYear

public static long firstOfYear(long date)
Returns the value for the first day in date's year.

Parameters:
date - a time in milli seconds
Returns:
the value for the first day in date's year.

getWeek

public static int getWeek(long time)
Method getWeek returns the week number for the supplied date.

Parameters:
time - a time in milli seconds with current timezone
Returns:
int the week number of the day

getDayOfMonth

public static int getDayOfMonth(long date)
Method getDayOfMonth.

Parameters:
date - as long
Returns:
int the day of mont 1..31

getWeekDay

public static int getWeekDay(long time)
Returns the weekday, from 1-7 where 1 = Sunday.

Parameters:
time - a time value
Returns:
the weekday, from 1-7 where 1 = Sunday.

parse

public long parse(java.lang.String string)
Parses the date string with the current formatter.

Parameters:
string - a date string
Returns:
-1 on error or the parsed time.

getMonth

public static int getMonth(long t)
the month the given date.

Parameters:
t - a time value
Returns:
1-12 for the given time value.

getYear

public static int getYear(long t)
the year for the given time value.

Parameters:
t - a time value
Returns:
1970-xxxx for the given time value.

firstOfDay

public static long firstOfDay(long t)
Returns a time value for the specified day at 00:00:00.000 with current time zone.

Parameters:
t - a time value
Returns:
a time value for the specified day at 00:00:00.000 with current time zone.