Package adams.core
Class DateFormat
- java.lang.Object
-
- adams.core.DateFormat
-
- All Implemented Interfaces:
TechnicalInformationHandler
,Serializable
public class DateFormat extends Object implements Serializable, TechnicalInformationHandler
A threadsafe class for date formatting/parsing.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
SimpleDateFormat
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_FORMAT
the default format.protected SimpleDateFormat
m_Format
the actual formatter/parser.
-
Constructor Summary
Constructors Constructor Description DateFormat()
Initializes the formatter.DateFormat(String format)
Initializes the formatter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyPattern(String pattern)
Sets a new pattern to use for formatting the dates.boolean
check(String source)
Checks whether the string can be parsed.String
format(Date date)
Returns the formatted string of the specified date object.Calendar
getCalendar()
Returns the currently used calendar.TechnicalInformation
getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.TimeZone
getTimeZone()
Returns the currently used timezone.boolean
isLenient()
Returns whether the parsing is lenient or not.Date
parse(String source)
Tries to parse the given string and turns it into a date object.void
setCalendar(Calendar value)
Sets the new calendar to use.void
setLenient(boolean value)
Sets whether parsing is to be lenient or not.void
setTimeZone(TimeZone value)
Sets the timezone to use.String
toPattern()
Returns the current pattern used for formatting the dates.String
toString()
Returns a string representation of the string formatter.
-
-
-
Field Detail
-
DEFAULT_FORMAT
public static final String DEFAULT_FORMAT
the default format.- See Also:
- Constant Field Values
-
m_Format
protected SimpleDateFormat m_Format
the actual formatter/parser.
-
-
Constructor Detail
-
DateFormat
public DateFormat()
Initializes the formatter.- See Also:
DEFAULT_FORMAT
-
DateFormat
public DateFormat(String format)
Initializes the formatter.- Parameters:
format
- the format to use- See Also:
SimpleDateFormat(String)
-
-
Method Detail
-
getTechnicalInformation
public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformation
in interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
applyPattern
public void applyPattern(String pattern)
Sets a new pattern to use for formatting the dates.- Parameters:
pattern
- the new pattern- See Also:
SimpleDateFormat.applyPattern(String)
-
toPattern
public String toPattern()
Returns the current pattern used for formatting the dates.- Returns:
- the current pattern
- See Also:
SimpleDateFormat.toPattern()
-
setCalendar
public void setCalendar(Calendar value)
Sets the new calendar to use.- Parameters:
value
- the new calendar- See Also:
DateFormat.setCalendar(Calendar)
-
getCalendar
public Calendar getCalendar()
Returns the currently used calendar.- Returns:
- the current calendar
- See Also:
DateFormat.getCalendar()
-
setTimeZone
public void setTimeZone(TimeZone value)
Sets the timezone to use.- Parameters:
value
- the new timezone- See Also:
DateFormat.setTimeZone(TimeZone)
-
getTimeZone
public TimeZone getTimeZone()
Returns the currently used timezone.- Returns:
- the current timezone
- See Also:
DateFormat.getTimeZone()
-
setLenient
public void setLenient(boolean value)
Sets whether parsing is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not- See Also:
DateFormat.setLenient(boolean)
-
isLenient
public boolean isLenient()
Returns whether the parsing is lenient or not.- Returns:
- true if parsing is lenient
- See Also:
DateFormat.isLenient()
-
format
public String format(Date date)
Returns the formatted string of the specified date object.- Parameters:
date
- the date to format- Returns:
- the generated string
- See Also:
DateFormat.format(Date)
-
parse
public Date parse(String source)
Tries to parse the given string and turns it into a date object. In contrast to SimpleDateFormat'sparse(String)
method, no exception is thrown here.- Parameters:
source
- the string to parse- Returns:
- the generated date object, or null in case of an error
- See Also:
DateFormat.parse(String)
-
check
public boolean check(String source)
Checks whether the string can be parsed. Does not throw an exception.- Parameters:
source
- the string to parse- Returns:
- true if string can be parsed
- See Also:
DateFormat.parse(String)
-
toString
public String toString()
Returns a string representation of the string formatter.- Overrides:
toString
in classObject
- Returns:
- the string
- See Also:
Object.toString()
-
-