public class DateParser
extends java.lang.Object
parseDate(String, String) and parseDate(String)
are able to understand some functions, that allows more efficient spefications.
| NOW() | The actual time in milli seconds. |
| SECONDS(int) | The duration in seconds. If the argument is empty, it will be interpreted as number of seconds of the minute of the current time. |
| MINUTES(int) | The duration in minutes. If the argument is empty, it will be interpreted as number of minutes of the hour of the current time. |
| HOURS(int) | The duration in hours. If the argument is empty, it will be interpreted as number of hours of the day of the current time. |
| DAYS(int) | The duration in days. If the argument is empty, it will be interpreted as number of days of the month of the current time. |
| MONTHS(int) | The duration in months. If the argument is empty, it will be interpreted as number of months of the year of the current time. |
| YEARS(int) | The duration in years. If the argument is empty, the year of the current time will be used. |
20080215-days(3)+hours(2)+minutes(2)-SECONDS(10000)
now()-days(3)+hours(2)+minutes(2)-SECONDS(10000)
| Modifier and Type | Class and Description |
|---|---|
protected static class |
DateParser.Part |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DAYS |
static long |
DAYS_FACTOR |
static java.lang.String |
DAYS_PATTERN |
static java.lang.String |
HOURS |
static long |
HOURS_FACTOR |
static java.lang.String |
HOURS_PATTERN |
static java.lang.String |
MINUTES |
static long |
MINUTES_FACTOR |
static java.lang.String |
MINUTES_PATTERN |
static java.lang.String |
MONTHS |
static long |
MONTHS_FACTOR |
static java.lang.String |
MONTHS_PATTERN |
static java.lang.String |
NOW |
static long |
NOW_FACTOR |
static java.lang.String |
NOW_PATTERN |
static java.lang.String |
SECONDS |
static long |
SECONDS_FACTOR |
static java.lang.String |
SECONDS_PATTERN |
static java.lang.String |
YEARS |
static long |
YEARS_FACTOR |
static java.lang.String |
YEARS_PATTERN |
| Constructor and Description |
|---|
DateParser() |
| Modifier and Type | Method and Description |
|---|---|
protected static long |
getTime(DateParser.Part part)
Get geth time in millis that is defined by the given part object.
|
static void |
main(java.lang.String[] args)
The testing program.
|
protected static long |
parse(java.lang.String literal,
java.lang.String format)
Parse a Date value from string.
|
protected static DateParser.Part |
parseDate(DateParser.Part part,
java.lang.String format)
Parsing a Part object.
|
static java.util.Date |
parseDate(java.lang.String literal)
Parse a Date value from string.
|
static java.util.Date |
parseDate(java.lang.String literal,
java.lang.String format)
Parse a Date value from string.
|
static java.util.Date |
parseDateFormat(java.lang.String literal,
java.lang.String format)
Parse a Date value from string based on SimpleDateFormat class only.
|
protected static DateParser.Part[] |
parseDateToPart(java.lang.String literal,
java.lang.String format)
Parsing a Part object.
|
protected static DateParser.Part |
parsePart(DateParser.Part part,
java.lang.String pattern,
long initial,
long factor)
Parsing a Part object.
|
protected static DateParser.Part[] |
parsePart(java.lang.String literal,
java.lang.String pattern,
long initial,
long factor)
Parsing a Part object.
|
public static final java.lang.String SECONDS
public static final java.lang.String SECONDS_PATTERN
public static final long SECONDS_FACTOR
public static final java.lang.String MINUTES
public static final java.lang.String MINUTES_PATTERN
public static final long MINUTES_FACTOR
public static final java.lang.String HOURS
public static final java.lang.String HOURS_PATTERN
public static final long HOURS_FACTOR
public static final java.lang.String DAYS
public static final java.lang.String DAYS_PATTERN
public static final long DAYS_FACTOR
public static final java.lang.String MONTHS
public static final java.lang.String MONTHS_PATTERN
public static final long MONTHS_FACTOR
public static final java.lang.String YEARS
public static final java.lang.String YEARS_PATTERN
public static final long YEARS_FACTOR
public static final java.lang.String NOW
public static final java.lang.String NOW_PATTERN
public static final long NOW_FACTOR
public static java.util.Date parseDateFormat(java.lang.String literal,
java.lang.String format)
throws java.text.ParseException
literal - The literalformat - the optional format, may be nulljava.text.ParseException - if parsing fails.SimpleDateFormatpublic static java.util.Date parseDate(java.lang.String literal,
java.lang.String format)
throws java.text.ParseException
literal - The literalformat - the optional format, may be nulljava.text.ParseException - if parsing fails.SimpleDateFormatpublic static java.util.Date parseDate(java.lang.String literal)
throws java.text.ParseException
literal - The literaljava.text.ParseException - if parsing fails.SimpleDateFormatprotected static long parse(java.lang.String literal,
java.lang.String format)
throws java.text.ParseException
literal - The literaljava.text.ParseException - if parsing fails.SimpleDateFormatprotected static long getTime(DateParser.Part part)
part - the parts.protected static DateParser.Part parsePart(DateParser.Part part, java.lang.String pattern, long initial, long factor) throws java.text.ParseException
part - the Part object to be parsed.pattern - the pattern to used for splitting literal.inital - the intial value, if function has no argument.factor - the factor for the parsed value to get the millis.an - parse exception, if the function argument is not parsable.java.text.ParseExceptionprotected static DateParser.Part[] parsePart(java.lang.String literal, java.lang.String pattern, long initial, long factor) throws java.text.ParseException
literal - the literal to be parsed.pattern - the pattern to used for splitting literal.inital - the intial value, if function has no argument.factor - the factor for the parsed value to get the millis.an - parse exception, if the function argument is not parsable.java.text.ParseExceptionprotected static DateParser.Part parseDate(DateParser.Part part, java.lang.String format) throws java.text.ParseException
part - the Part object to be parsed.format - the optional format, may be nullan - parse exception, if the function argument is not parsable.java.text.ParseExceptionprotected static DateParser.Part[] parseDateToPart(java.lang.String literal, java.lang.String format) throws java.text.ParseException
literal - the literal to be parsed.format - the optional format, may be nullan - parse exception, if the function argument is not parsable.java.text.ParseExceptionpublic static void main(java.lang.String[] args)
args -