Framework Professional Edition Package


com.prosyst.util.text
Class DateFormat

java.lang.Object
  extended by com.prosyst.util.text.DateFormat

public class DateFormat
extends java.lang.Object

Class utilizing the work with specific date format, often defined in rfc-s. The class supports construction of RFC1123 date and parsing of RFC1036, RFC1123, and ANSI C's asctime() formats. Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format


Field Summary
protected static java.util.Calendar calendar
           
protected static java.util.Date date
           
protected static java.lang.String[] MONTH_NAMES
           
protected static java.lang.String[] WEEK_DAYS
           
protected static java.util.TimeZone zone
           
 
Constructor Summary
DateFormat()
           
 
Method Summary
protected static void appendInt(java.lang.StringBuffer stringbuffer, int i)
          Appends the int to the string buffer, without creation of char[] and string objects.
static java.lang.String format()
          Constructs a new date with time zone "GMT", US locale and date - current date.
static java.lang.String format(long l)
          Constructs a new date with time zone "GMT", US locale and date defined by l milliseconds.
static java.lang.String format(long l, java.lang.StringBuffer sb)
          Constructs a new date with time zone "GMT", US locale and date defined by l milliseconds.
protected static void formatDoubleDigit(java.lang.StringBuffer stringbuffer, int i)
          Appends to the string buffer the number passed, formatting it as a two digit string.
protected static int locateMonth(java.lang.String s)
          Gets the index from MONTH_NAMES array of the month string passed, i.e if "Jan" is passed, the method will retrive 0.
static long parse(java.lang.String s)
          Test if the string conforms with any of supported date formats and returns the date value (in milliseconds since 1 January, 1970) that matches the string.
static long parseASC(java.lang.String s)
          Parses a string, formatted in ANSI C's asctime.
static long parseRFC1036(java.lang.String s)
          Parses a string, formatted according to RFC1036 date.
static long parseRFC1123(java.lang.String s)
          Parses a string, formatted according to RFC1123 date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

zone

protected static final java.util.TimeZone zone

MONTH_NAMES

protected static final java.lang.String[] MONTH_NAMES

WEEK_DAYS

protected static final java.lang.String[] WEEK_DAYS

calendar

protected static java.util.Calendar calendar

date

protected static java.util.Date date
Constructor Detail

DateFormat

public DateFormat()
Method Detail

format

public static java.lang.String format()
Constructs a new date with time zone "GMT", US locale and date - current date.

Returns:
the date formatted according RFC 1123.

format

public static java.lang.String format(long l)
Constructs a new date with time zone "GMT", US locale and date defined by l milliseconds.

Parameters:
l - milliseconds to create a date with
Returns:
the date formatted according RFC 1123.

format

public static java.lang.String format(long l,
                                      java.lang.StringBuffer sb)
Constructs a new date with time zone "GMT", US locale and date defined by l milliseconds.

Parameters:
l - milliseconds to create a date with
sb - the string buffer, where to append the formatted date, can be null
Returns:
the date formatted according RFC 1123.

parse

public static long parse(java.lang.String s)
                  throws java.lang.IllegalArgumentException
Test if the string conforms with any of supported date formats and returns the date value (in milliseconds since 1 January, 1970) that matches the string.

Parameters:
s - string to parse.
Returns:
milliseconds since 1 January, 1970
Throws:
java.lang.IllegalArgumentException - if the string format does not match any of the supported standards

parseASC

public static long parseASC(java.lang.String s)
                     throws java.lang.IllegalArgumentException
Parses a string, formatted in ANSI C's asctime.

Parameters:
s - date to parse; must be in ANSI C's asctime format. e.g.: Sun Nov 6 08:49:37 1994
Returns:
milliseconds since 1 January, 1970
Throws:
java.lang.IllegalArgumentException - if incorrectly formatted

parseRFC1036

public static long parseRFC1036(java.lang.String s)
                         throws java.lang.IllegalArgumentException
Parses a string, formatted according to RFC1036 date.

Parameters:
s - date to parse; must be in RFC1036 format. e.g.: Sunday, 06-Nov-94 08:49:37 GMT
Returns:
milliseconds since 1 January, 1970
Throws:
java.lang.IllegalArgumentException - if incorrectly formatted

parseRFC1123

public static long parseRFC1123(java.lang.String s)
                         throws java.lang.IllegalArgumentException
Parses a string, formatted according to RFC1123 date.

Parameters:
s - date to parse; must be in RFC1123 format. e.g.: Sun, 06 Nov 1994 08:49:37 GMT
Returns:
milliseconds since 1 January, 1970
Throws:
java.lang.IllegalArgumentException - if incorrectly formatted

locateMonth

protected static int locateMonth(java.lang.String s)
                          throws java.lang.NumberFormatException
Gets the index from MONTH_NAMES array of the month string passed, i.e if "Jan" is passed, the method will retrive 0. Months' indexes are from 0 to 11. This index can be used as a valid java.util.Calender's id for month.

Parameters:
s - a three letter US.Locale month name.
Returns:
month index
Throws:
java.lang.NumberFormatException - When moth string is invalid three letter name.

formatDoubleDigit

protected static void formatDoubleDigit(java.lang.StringBuffer stringbuffer,
                                        int i)
Appends to the string buffer the number passed, formatting it as a two digit string. Each digit is preceded by '0', e.g. "3" is appended to the string buffer as "03", while "12" is appended as is: "12".

Parameters:
stringbuffer - to append number i to
i - to be formatted as two digits.

appendInt

protected static void appendInt(java.lang.StringBuffer stringbuffer,
                                int i)
Appends the int to the string buffer, without creation of char[] and string objects.


Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved