Package org.supercsv.cellprocessor
Class FmtDate
- java.lang.Object
-
- org.supercsv.cellprocessor.CellProcessorAdaptor
-
- org.supercsv.cellprocessor.FmtDate
-
- All Implemented Interfaces:
CellProcessor
,DateCellProcessor
public class FmtDate extends CellProcessorAdaptor implements DateCellProcessor
Converts a date into a formatted string using theSimpleDateFormat
class. If you want to convert from a String to a Date, use theParseDate
processor.Some example date formats you can use are:
"dd/MM/yyyy"
(formats a date as "25/12/2011")
"dd-MMM-yy"
(formats a date as "25-Dec-11")
"yyyy.MM.dd.HH.mm.ss"
(formats a date as "2011.12.25.08.36.33"
"E, dd MMM yyyy HH:mm:ss Z"
(formats a date as "Tue, 25 Dec 2011 08:36:33 -0500")- Since:
- 1.50
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
dateFormat
-
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
-
Constructor Summary
Constructors Constructor Description FmtDate(java.lang.String dateFormat)
Constructs a new FmtDate processor, which converts a date into a formatted string using SimpleDateFormat.FmtDate(java.lang.String dateFormat, StringCellProcessor next)
Constructs a new FmtDate processor, which converts a date into a formatted string using SimpleDateFormat, then calls the next processor in the chain.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkPreconditions(java.lang.String dateFormat)
Checks the preconditions for creating a new FmtDate processor.java.lang.Object
execute(java.lang.Object value, CsvContext context)
This method is invoked by the framework when the processor needs to process data or check constraints.-
Methods inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
toString, validateInputNotNull
-
-
-
-
Constructor Detail
-
FmtDate
public FmtDate(java.lang.String dateFormat)
Constructs a new FmtDate processor, which converts a date into a formatted string using SimpleDateFormat.- Parameters:
dateFormat
- the date format String (seeSimpleDateFormat
)- Throws:
java.lang.NullPointerException
- if dateFormat is null
-
FmtDate
public FmtDate(java.lang.String dateFormat, StringCellProcessor next)
Constructs a new FmtDate processor, which converts a date into a formatted string using SimpleDateFormat, then calls the next processor in the chain.- Parameters:
dateFormat
- the date format String (seeSimpleDateFormat
)next
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if dateFormat or next is null
-
-
Method Detail
-
checkPreconditions
private static void checkPreconditions(java.lang.String dateFormat)
Checks the preconditions for creating a new FmtDate processor.- Parameters:
dateFormat
- the date format String- Throws:
java.lang.NullPointerException
- if dateFormat is null
-
execute
public java.lang.Object execute(java.lang.Object value, CsvContext context)
This method is invoked by the framework when the processor needs to process data or check constraints.- Specified by:
execute
in interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is null or is not a Date, or if dateFormat is not a valid date format
-
-