wt.util
Class WTStandardDateFormat

java.lang.Object
  extended bywt.util.WTStandardDateFormat

public class WTStandardDateFormat
extends Object

WTStandardDateFormat

This class provides methods to create display strings from Date objects. The methods may take as arguments, not only a Date, but also various combinations of format type, format string, Locale and TimeZone.

There are currently two standard formats defined: "long" and "short". "long" is the default format for methods which do not take a format argument. The format strings are in wt.util.utilResource.rbInfo.

Locale and TimeZone values default to those provided by WTContext methods.

Examples:

WTStandardDateFormat.format(myDate)
returns: "1998-05-28 14:22:35 CST"
WTStandardDateFormat.format(myDate, WTStandardDateFormat.SHORT_STANDARD_DATE_FORMAT)
returns: "98 May 28 14:22"


Supported API: true
Extendable: false

See Also:
Date, SimpleDateFormat

Field Summary
private static Object createSync
           
static boolean DEBUG
           
static int EXPLORER_STANDARD_DATE_FORMAT
          Format for the default locale is 'M/dd/yy h:mm a'.
static int EXPLORER_STANDARD_DATE_ONLY_FORMAT
          Format for the default locale is 'M/dd/yy'.
static int EXPLORER_STANDARD_TIME_ONLY_FORMAT
          Format for the default locale is 'h:mm a'.
private static Hashtable localeFormatCache
           
static int LONG_STANDARD_DATE_FORMAT
          Format for the default locale is 'yyyy-MM-dd HH:mm:ss z'.
static int LONG_STANDARD_DATE_FORMAT_MINUS_TIME
          Format for the default locale is 'yyyy-MM-dd'.
static int LONG_STANDARD_DATE_FORMAT_MINUS_TIMEZONE
          Format for the default locale is 'yyyy-MM-dd HH:mm:ss'.
private static String RESOURCE
           
static int SHORT_STANDARD_DATE_FORMAT
          Format for the default locale is 'dd MMM yy HH:mm'.
private static String versionID
           
static int WF_STANDARD_DATE_ONLY_FORMAT
          Format for the default locale is 'MM/dd/yyyy'.
 
Constructor Summary
WTStandardDateFormat()
          No-arg constructor.
 
Method Summary
static String format(Date date)
          Formats a Date into a date/time string.
static String format(Date date, int formatType)
          Formats a Date into a date/time string.
static String format(Date date, int formatType, Locale locale)
          Formats a Date into a date/time string.
static String format(Date date, int formatType, Locale locale, TimeZone timeZone)
          Formats a Date into a date/time string.
static String format(Date date, Locale locale)
          Formats a Date into a date/time string.
static String format(Date date, String formatString)
          Formats a Date into a date/time string.
static String format(Date date, String formatString, Locale locale, TimeZone timeZone)
          Formats a Date into a date/time string.
static int formatTypeFromString(String formatTypeString)
          Converts the name of the format type to the constant that it represents.
private static Hashtable getSimpleDateCache(Locale locale)
           
static void main(String[] args)
          Parse a date and format it for display.
static Date parse(String date)
          Parses text from a string in the format LONG_STANDARD_DATE_FORMAT to produce a Date.
static Date parse(String date, int formatType)
          Parses text from a string to produce a Date.
static Date parse(String date, int formatType, Locale locale, TimeZone timeZone)
          Parses text from a string to produce a Date.
static Date parse(String date, Locale locale)
          Parses text from a string in the format LONG_STANDARD_DATE_FORMAT to produce a Date.
static Date parse(String date, String formatString)
          Parses text from a string to produce a Date.
static Date parse(String date, String formatString, Locale locale, TimeZone timeZone)
          Parses text from a string to produce a Date.
private static SimpleDateFormat popSimpleDateFormat(Locale locale, String formatString)
           
private static void pushSimpleDateFormat(SimpleDateFormat sdf, Locale locale, String formatString)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionID

private static final String versionID
See Also:
Constant Field Values

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

LONG_STANDARD_DATE_FORMAT

public static final int LONG_STANDARD_DATE_FORMAT
Format for the default locale is 'yyyy-MM-dd HH:mm:ss z'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

SHORT_STANDARD_DATE_FORMAT

public static final int SHORT_STANDARD_DATE_FORMAT
Format for the default locale is 'dd MMM yy HH:mm'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

EXPLORER_STANDARD_DATE_FORMAT

public static final int EXPLORER_STANDARD_DATE_FORMAT
Format for the default locale is 'M/dd/yy h:mm a'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

EXPLORER_STANDARD_DATE_ONLY_FORMAT

public static final int EXPLORER_STANDARD_DATE_ONLY_FORMAT
Format for the default locale is 'M/dd/yy'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

EXPLORER_STANDARD_TIME_ONLY_FORMAT

public static final int EXPLORER_STANDARD_TIME_ONLY_FORMAT
Format for the default locale is 'h:mm a'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

WF_STANDARD_DATE_ONLY_FORMAT

public static final int WF_STANDARD_DATE_ONLY_FORMAT
Format for the default locale is 'MM/dd/yyyy'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

LONG_STANDARD_DATE_FORMAT_MINUS_TIMEZONE

public static final int LONG_STANDARD_DATE_FORMAT_MINUS_TIMEZONE
Format for the default locale is 'yyyy-MM-dd HH:mm:ss'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

LONG_STANDARD_DATE_FORMAT_MINUS_TIME

public static final int LONG_STANDARD_DATE_FORMAT_MINUS_TIME
Format for the default locale is 'yyyy-MM-dd'. This may vary with other locales.

Supported API: true
Extendable: false

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

localeFormatCache

private static Hashtable localeFormatCache

createSync

private static Object createSync
Constructor Detail

WTStandardDateFormat

public WTStandardDateFormat()
No-arg constructor.

Supported API: true

Method Detail

formatTypeFromString

public static int formatTypeFromString(String formatTypeString)
Converts the name of the format type to the constant that it represents.

Parameters:
formatTypeString - The name of the format type. Valid values are:
  • "LONG_STANDARD_DATE_FORMAT"
  • "SHORT_STANDARD_DATE_FORMAT"
  • "WF_STANDARD_DATE_ONLY_FORMAT"
  • "EXPLORER_STANDARD_DATE_FORMAT"
  • "EXPLORER_STANDARD_DATE_ONLY_FORMAT"
  • "EXPLORER_STANDARD_TIME_ONLY_FORMAT"
  • "LONG_STANDARD_DATE_FORMAT_MINUS_TIMEZONE"
  • "LONG_STANDARD_DATE_FORMAT_MINUS_TIME"
Returns:
The format type:

Supported API: true
Extendable: false

format

public static String format(Date date,
                            String formatString,
                            Locale locale,
                            TimeZone timeZone)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
formatString - The format string (see java.text.SimpleDateFormat).
locale - The locale.
timeZone - The given new time zone.
Returns:
The formatted date-time string.

Supported API: true
Extendable: false

format

public static String format(Date date,
                            int formatType,
                            Locale locale,
                            TimeZone timeZone)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
formatType - The format. Valid values are:
locale - The locale whose date format symbols should be used.
timeZone - The given new time zone.
Returns:
The formatted date-time string.

Supported API: true
Extendable: false

format

public static String format(Date date,
                            String formatString)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
formatString - The format string (see java.text.SimpleDateFormat).
Returns:
The formatted date-time string.

Supported API: true
Extendable: false

format

public static String format(Date date,
                            int formatType,
                            Locale locale)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
formatType - The format. Valid values are:
locale - The locale whose date format symbols should be used.
Returns:
The formatted date-time string.

Supported API: true
Extendable: false

format

public static String format(Date date,
                            int formatType)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
formatType - The format. Valid values are:
Returns:
The formatted date-time string.

Supported API: true
Extendable: false

format

public static String format(Date date,
                            Locale locale)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
locale - The locale whose date format symbols should be used.
Returns:
The formatted date-time string in LONG_STANDARD_DATE_FORMAT format.

Supported API: true
Extendable: false

format

public static String format(Date date)
Formats a Date into a date/time string.

Parameters:
date - The date to be formatted into a String.
Returns:
The formatted date-time string in LONG_STANDARD_DATE_FORMAT format.

Supported API: true
Extendable: false

parse

public static Date parse(String date,
                         String formatString,
                         Locale locale,
                         TimeZone timeZone)
                  throws ParseException
Parses text from a string to produce a Date.

Parameters:
date - The string to parse.
formatString - The format string (see java.text.SimpleDateFormat).
locale - The locale.
timeZone - The time zone to use in parsing.
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

parse

public static Date parse(String date,
                         int formatType,
                         Locale locale,
                         TimeZone timeZone)
                  throws ParseException
Parses text from a string to produce a Date.

Parameters:
date - The string to parse.
formatType - The format. Valid values are:
locale - The locale.
timeZone - The time zone to use in parsing.
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

parse

public static Date parse(String date,
                         String formatString)
                  throws ParseException
Parses text from a string to produce a Date.

Parameters:
date - The string to parse.
formatString - The format string (see java.text.SimpleDateFormat).
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

parse

public static Date parse(String date,
                         int formatType)
                  throws ParseException
Parses text from a string to produce a Date.

Parameters:
date - The string to parse.
formatType - The format. Valid values are:
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

parse

public static Date parse(String date,
                         Locale locale)
                  throws ParseException
Parses text from a string in the format LONG_STANDARD_DATE_FORMAT to produce a Date.

Parameters:
date - The string to parse.
locale - The locale.
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

parse

public static Date parse(String date)
                  throws ParseException
Parses text from a string in the format LONG_STANDARD_DATE_FORMAT to produce a Date.

Parameters:
date - The string to parse.
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
ParseException -

Supported API: true
Extendable: false

popSimpleDateFormat

private static SimpleDateFormat popSimpleDateFormat(Locale locale,
                                                    String formatString)

pushSimpleDateFormat

private static void pushSimpleDateFormat(SimpleDateFormat sdf,
                                         Locale locale,
                                         String formatString)

getSimpleDateCache

private static Hashtable getSimpleDateCache(Locale locale)

main

public static void main(String[] args)
Parse a date and format it for display.
   Example Usage:
      // for current user's locale
      java wt.util.WTStandardDateFormat "2003-07-21 19:02:23.0"
                                        "yyyy-MM-dd HH:mm:ss.S" "MM/dd/yyyy hh:mm:ss a z"
 

// for FRENCH locale java wt.util.WTStandardDateFormat "2003-07-21 19:02:23.0" "yyyy-MM-dd HH:mm:ss.S" "MM/dd/yyyy hh:mm:ss a z" fr

Parameters:
args - a String[] containing the following elements:

[0] a date

[1] format of passed string to parse into a date

[2] format to use to display parsed date

[3] a locale code

[4] a timezone id

See Also:
Locale, SimpleTimeZone, - for formating codes

Supported API: false
Extendable: false