dsto.dfc.text
Class MultiDateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
          extended by java.text.SimpleDateFormat
              extended by dsto.dfc.text.MultiDateFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
InputDateFormat, IsoDateFormat

public class MultiDateFormat
extends SimpleDateFormat

Title: MultiDateFormat Description: MultiDateFormat is DateFormat defined with more than one format. It parses using all of these formats, but formats using only the one. Parsing is done in order as given in the constructor. If you provide two formats that could read the same date, this class will use the first one. If you have extended versions of the pattern, i.e. YYYY-MM-DD and YYYY-MM-DD T hh:mm, you should place the longer ones first.

Copyright: Copyright (c) 2001

Version:
1.0
Author:
Paul Hill goodhill@xmission.com
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field
 
Field Summary
protected  DateFormat defaultFormat
          The format to use to create a String from a Date.
protected  DateFormat[] parseFormat
          List of possible formats with which to parse a String
 
Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
 
Constructor Summary
MultiDateFormat(DateFormat[] someParseFormats)
          Construct a MultiDateFormat using the given DateFormats and setting the default format pattern.
MultiDateFormat(DateFormat[] someParseFormats, DateFormat aDefaultFormat)
          Construct a MultiDateFormat using the given DateFormats.
 
Method Summary
 StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)
          Formats a Date into a date/time string using the default format.
 Date parse(String text, ParsePosition pos)
          Overrides DateFormat.parse to try all possible formats
 Object parseObject(String source)
          Format.parseObject () generates useless generic message on error.
 void setDefaultFormat(DateFormat aFormat)
          Set a different DateFormat as the format to use when calling format.
 
Methods inherited from class java.text.SimpleDateFormat
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
 
Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
 
Methods inherited from class java.text.Format
format
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parseFormat

protected DateFormat[] parseFormat
List of possible formats with which to parse a String


defaultFormat

protected DateFormat defaultFormat
The format to use to create a String from a Date.

Constructor Detail

MultiDateFormat

public MultiDateFormat(DateFormat[] someParseFormats,
                       DateFormat aDefaultFormat)
Construct a MultiDateFormat using the given DateFormats. Set

Parameters:
someParseFormats - an array of formats which to try in order when parsing.
aDefaultFormat - the format to use create a String from a Date.
See Also:
SimpleDateFormat

MultiDateFormat

public MultiDateFormat(DateFormat[] someParseFormats)
Construct a MultiDateFormat using the given DateFormats and setting the default format pattern.

See Also:
SimpleDateFormat
Method Detail

format

public StringBuffer format(Date date,
                           StringBuffer toAppendTo,
                           FieldPosition fieldPosition)
Formats a Date into a date/time string using the default format.

Overrides:
format in class SimpleDateFormat
Parameters:
date - a Date to for formatting into a date/time string.
toAppendTo - the string buffer in which return a date/time string.
fieldPosition - contains the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the requested field.
Returns:
a StringBuilder with the Date formated in it.
See Also:
DateFormat

parseObject

public Object parseObject(String source)
                   throws ParseException
Format.parseObject () generates useless generic message on error. Do slightly better

Overrides:
parseObject in class Format
Throws:
ParseException

parse

public Date parse(String text,
                  ParsePosition pos)
Overrides DateFormat.parse to try all possible formats

Overrides:
parse in class SimpleDateFormat
See Also:
DateFormat

setDefaultFormat

public void setDefaultFormat(DateFormat aFormat)
Set a different DateFormat as the format to use when calling format.



Copyright © 2008 Commonwealth of Australia