public class RelativeDateParser
extends java.lang.Object
Constructor and Description |
---|
RelativeDateParser() |
Modifier and Type | Method and Description |
---|---|
static java.util.Date |
parseRelativeDate(java.lang.String dateTemplate)
Returns a date which is less than current system date/time on a specified number of days, years, minutes, weeks
etc.
A common template which is valid for this method is like that:
XXXXy XXXXM XXXXw XXXXd XXXXh XXXXm XXXXs, where: |
public static java.util.Date parseRelativeDate(java.lang.String dateTemplate) throws java.text.ParseException
XXXX - any positive number composed of four or less digits, but not less that one digit y - this symbol represents how many years must be subtracted from current system date M - this symbol represents how many months must be subtracted from current system date w - this symbol represents how many weeks must be subtracted rom current system date d - this symbol represents how many days must be subtracted from current system date h - this symbol represents how many hours must be subtracted from current system date m - this symbol represents how many minutes must be subtracted from current system date s - this symbol represents how many seconds must be subtracted from current system dateAbove symbols are called "modifiers".
Modifiers are case sensitive. Modifiers separated by single space character or sequence of spaces. Each modifier is optional, but an order of modifiers is matter and must be exactly the same how its specified in template.
Here is a few examples of date templates and its meanings:"4h 3m 23s"
- means 4 hours, 3 minutes and 23 seconds ago from current system date"1y 2m 3w"
- means 1 year, 2 months and 3 weeks ago from current system date"1m 1w 13h 5m"
- means 1 month, 1 week, 13 hours and 5 minutes ago from current system datedateTemplate
- a template of a date we want to be calculatedDate
object that is applies specified templatejava.text.ParseException
- if some problems were occurred while parsing specified date template