public class ISODateIO
extends java.lang.Object
Calendar
for convenience.
Format of the scanner can be composed of %? directive which define components
of the time. These directives are listed below. For example, the format
"%F %T", which is equivalent to "%Y-%m-%d %H:%M:%S" can parse the following
timestamp: "2010-12-09 03:45:39";
Modifier and Type | Field and Description |
---|---|
protected java.util.LinkedList<ISODateComponent> |
components
List of components, build from a string format.
|
private static ISODateComponent[] |
KNOWN_COMPONENTS |
protected java.util.regex.Pattern |
pattern
The regular expression builds from the components.
|
Constructor and Description |
---|
ISODateIO()
Create a scanner with default format "%K".
|
ISODateIO(java.lang.String format)
Create a new scanner with a given format.
|
Modifier and Type | Method and Description |
---|---|
protected void |
buildRegularExpression()
Build a regular expression from the components of the scanner.
|
protected java.util.LinkedList<ISODateComponent> |
findComponents(java.lang.String format)
Build a list of component from a string.
|
java.util.regex.Pattern |
getPattern()
Get the current pattern used to parse timestamp.
|
java.util.Calendar |
parse(java.lang.String time)
Parse a string which should be in the scanner format.
|
void |
setFormat(java.lang.String format)
Set the format of this scanner.
|
java.lang.String |
toString(java.util.Calendar calendar)
Convert a calendar into a string according to the format of this object.
|
private static final ISODateComponent[] KNOWN_COMPONENTS
protected java.util.LinkedList<ISODateComponent> components
protected java.util.regex.Pattern pattern
public ISODateIO() throws java.text.ParseException
java.text.ParseException
public ISODateIO(java.lang.String format) throws java.text.ParseException
format
- format of the scanner.java.text.ParseException
- if bad directives foundpublic java.util.regex.Pattern getPattern()
protected java.util.LinkedList<ISODateComponent> findComponents(java.lang.String format) throws java.text.ParseException
format
- format of the scannerjava.text.ParseException
- if invalid component foundprotected void buildRegularExpression()
public void setFormat(java.lang.String format) throws java.text.ParseException
format
- new format of the scannerjava.text.ParseException
- if an error is found in the new formatpublic java.util.Calendar parse(java.lang.String time)
time
- timestamp in the scanner formatpublic java.lang.String toString(java.util.Calendar calendar)
calendar
- the calendar to convert