public class DateConversion extends ObjectConversion<Date> implements FormattedConversion<SimpleDateFormat>
Date
and vice versa.
This class supports multiple date formats. For example, you can define conversions from dates represented by different Strings such as "2001/05/02 and Dec/2013".
The reverse conversion from a Date to String (in revert(Date)
will return a formatted String using the date pattern provided in this class constructor
The date patterns must follows the pattern rules of SimpleDateFormat
SimpleDateFormat
Constructor and Description |
---|
DateConversion(Date valueIfStringIsNull,
String valueIfObjectIsNull,
String... dateFormats)
Defines a conversion from String to
Date using a sequence of acceptable date patterns. |
DateConversion(Locale locale,
Date valueIfStringIsNull,
String valueIfObjectIsNull,
String... dateFormats)
Defines a conversion from String to
Date using a sequence of acceptable date patterns. |
DateConversion(Locale locale,
String... dateFormats)
Defines a conversion from String to
Date using a sequence of acceptable date patterns. |
DateConversion(String... dateFormats)
Defines a conversion from String to
Date using a sequence of acceptable date patterns. |
DateConversion(TimeZone timeZone,
Locale locale,
Date valueIfStringIsNull,
String valueIfObjectIsNull,
String... dateFormats)
Defines a conversion from String to
Date using a sequence of acceptable date patterns. |
Modifier and Type | Method and Description |
---|---|
protected Date |
fromString(String input)
Converts a formatted date String to an instance of Date.
|
SimpleDateFormat[] |
getFormatterObjects()
Returns the formatter objects
|
TimeZone |
getTimeZone() |
String |
revert(Date input)
Converts Date to a formatted date String.
|
execute, fromInput, getValueIfObjectIsNull, getValueIfStringIsNull, setValueIfObjectIsNull, setValueIfStringIsNull, undo
getValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutput
public DateConversion(TimeZone timeZone, Locale locale, Date valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)
Date
using a sequence of acceptable date patterns.
This constructor assumes the output of a conversion should be null when input is nulltimeZone
- the TimeZone
of the date to be formattedlocale
- the Locale
that determines how the date mask should be formatted.valueIfStringIsNull
- default Date value to be returned when the input String is null. Used when ObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a Date input is null. Used when revert(Date)
is invoked.dateFormats
- list of acceptable date patterns The first pattern in this sequence will be used to convert a Date into a String in revert(Date)
.public DateConversion(Locale locale, Date valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)
Date
using a sequence of acceptable date patterns.
This constructor assumes the output of a conversion should be null when input is nulllocale
- the Locale
that determines how the date mask should be formatted.valueIfStringIsNull
- default Date value to be returned when the input String is null. Used when ObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a Date input is null. Used when revert(Date)
is invoked.dateFormats
- list of acceptable date patterns The first pattern in this sequence will be used to convert a Date into a String in revert(Date)
.public DateConversion(Date valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)
Date
using a sequence of acceptable date patterns.
This constructor assumes the output of a conversion should be null when input is nullvalueIfStringIsNull
- default Date value to be returned when the input String is null. Used when ObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a Date input is null. Used when revert(Date)
is invoked.dateFormats
- list of acceptable date patterns The first pattern in this sequence will be used to convert a Date into a String in revert(Date)
.public DateConversion(Locale locale, String... dateFormats)
Date
using a sequence of acceptable date patterns.
This constructor assumes the output of a conversion should be null when input is nulllocale
- the Locale
that determines how the date mask should be formatted.dateFormats
- list of acceptable date patterns The first pattern in this sequence will be used to convert a Date into a String in revert(Date)
.public DateConversion(String... dateFormats)
Date
using a sequence of acceptable date patterns.
This constructor assumes the output of a conversion should be null when input is nulldateFormats
- list of acceptable date patterns The first pattern in this sequence will be used to convert a Date into a String in revert(Date)
.public String revert(Date input)
The pattern used to generate the formatted date is the first date pattern provided in the constructor of this class
revert
in interface Conversion<String,Date>
revert
in class ObjectConversion<Date>
input
- the Date to be converted to a StringvalueIfObjectIsNull
if the Date parameter is null.protected Date fromString(String input)
The pattern in the formatted date must match one of the date patterns provided in the constructor of this class.
fromString
in class ObjectConversion<Date>
input
- the String containing a formatted date which must be converted to a DatevalueIfObjectIsNull
if the String input is null.public SimpleDateFormat[] getFormatterObjects()
FormattedConversion
getFormatterObjects
in interface FormattedConversion<SimpleDateFormat>
public TimeZone getTimeZone()
Copyright © 2019 Univocity Software Pty Ltd. All rights reserved.