FileDocCategorySizeDatePackage
DateFormatManager.javaAPI DocApache log4j 1.2.156799Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5.util

DateFormatManager

public class DateFormatManager extends Object
Date format manager. Utility class to help manage consistent date formatting and parsing. It may be advantageous to have multiple DateFormatManagers per application. For example, one for handling the output (formatting) of dates, and another one for handling the input (parsing) of dates.
author
Robert Shaw
author
Michael J. Sikorsky

Fields Summary
private TimeZone
_timeZone
private Locale
_locale
private String
_pattern
private DateFormat
_dateFormat
Constructors Summary
public DateFormatManager()


  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------
    
    super();
    configure();
  
public DateFormatManager(TimeZone timeZone)

    super();

    _timeZone = timeZone;
    configure();
  
public DateFormatManager(Locale locale)

    super();

    _locale = locale;
    configure();
  
public DateFormatManager(String pattern)

    super();

    _pattern = pattern;
    configure();
  
public DateFormatManager(TimeZone timeZone, Locale locale)

    super();

    _timeZone = timeZone;
    _locale = locale;
    configure();
  
public DateFormatManager(TimeZone timeZone, String pattern)

    super();

    _timeZone = timeZone;
    _pattern = pattern;
    configure();
  
public DateFormatManager(Locale locale, String pattern)

    super();

    _locale = locale;
    _pattern = pattern;
    configure();
  
public DateFormatManager(TimeZone timeZone, Locale locale, String pattern)

    super();

    _timeZone = timeZone;
    _locale = locale;
    _pattern = pattern;
    configure();
  
Methods Summary
private synchronized voidconfigure()

    _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL,
        DateFormat.FULL,
        getLocale());
    _dateFormat.setTimeZone(getTimeZone());

    if (_pattern != null) {
      ((SimpleDateFormat) _dateFormat).applyPattern(_pattern);
    }
  
public java.lang.Stringformat(java.util.Date date)

    return getDateFormatInstance().format(date);
  
public java.lang.Stringformat(java.util.Date date, java.lang.String pattern)

    DateFormat formatter = null;
    formatter = getDateFormatInstance();
    if (formatter instanceof SimpleDateFormat) {
      formatter = (SimpleDateFormat) (formatter.clone());
      ((SimpleDateFormat) formatter).applyPattern(pattern);
    }
    return formatter.format(date);
  
public synchronized java.text.DateFormatgetDateFormatInstance()

    return _dateFormat;
  
public synchronized java.util.LocalegetLocale()

    if (_locale == null) {
      return Locale.getDefault();
    } else {
      return _locale;
    }
  
public synchronized java.lang.StringgetOutputFormat()
This method has been deprecated in favour of getPattern().

deprecated
Use getPattern().

    return _pattern;
  
public synchronized java.lang.StringgetPattern()

    return _pattern;
  
public synchronized java.util.TimeZonegetTimeZone()

    if (_timeZone == null) {
      return TimeZone.getDefault();
    } else {
      return _timeZone;
    }
  
public java.util.Dateparse(java.lang.String date)

throws
java.text.ParseException

    return getDateFormatInstance().parse(date);
  
public java.util.Dateparse(java.lang.String date, java.lang.String pattern)

throws
java.text.ParseException

    DateFormat formatter = null;
    formatter = getDateFormatInstance();
    if (formatter instanceof SimpleDateFormat) {
      formatter = (SimpleDateFormat) (formatter.clone());
      ((SimpleDateFormat) formatter).applyPattern(pattern);
    }
    return formatter.parse(date);
  
public synchronized voidsetDateFormatInstance(java.text.DateFormat dateFormat)

    _dateFormat = dateFormat;
    // No reconfiguration necessary!
  
public synchronized voidsetLocale(java.util.Locale locale)

    _locale = locale;
    configure();
  
public synchronized voidsetOutputFormat(java.lang.String pattern)
This method has been deprecated in favour of setPattern().

deprecated
Use setPattern().

    _pattern = pattern;
    configure();
  
public synchronized voidsetPattern(java.lang.String pattern)
Set the pattern. i.e. "EEEEE, MMMMM d, yyyy hh:mm aaa"

    _pattern = pattern;
    configure();
  
public synchronized voidsetTimeZone(java.util.TimeZone timeZone)

    _timeZone = timeZone;
    configure();