public class TimeCategory
extends Object
A dequirked, java.util.Date-flavored parallel to the legacy
groovy.time.TimeCategory. Use as:
use (org.apache.groovy.dateutil.TimeCategory) {
println 1.minute.from.now
println 10.hours.ago
def someDate = new Date()
println someDate - 3.months
}
Differences from the legacy class: the deprecated getTimeZone and the
getDaylightSavingsOffset helpers are dropped, and .ago/.from.now
preserve the time-of-day (see BaseDuration).
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Duration |
getDay(Integer self)Same day duration as getDays(Integer). |
|
public static Duration |
getDays(Integer self)A Duration of self days. |
|
public static TimeDuration |
getHour(Integer self)Same hour duration as getHours(Integer). |
|
public static TimeDuration |
getHours(Integer self)A TimeDuration of self hours. |
|
public static TimeDuration |
getMillisecond(Integer self)Same millisecond duration as getMilliseconds(Integer). |
|
public static TimeDuration |
getMilliseconds(Integer self)A TimeDuration of self milliseconds. |
|
public static TimeDuration |
getMinute(Integer self)Same minute duration as getMinutes(Integer). |
|
public static TimeDuration |
getMinutes(Integer self)A TimeDuration of self minutes. |
|
public static DatumDependentDuration |
getMonth(Integer self)Same month duration as getMonths(Integer). |
|
public static DatumDependentDuration |
getMonths(Integer self)A DatumDependentDuration whose month component is self. |
|
public static TimeDuration |
getSecond(Integer self)Same second duration as getSeconds(Integer). |
|
public static TimeDuration |
getSeconds(Integer self)A TimeDuration of self seconds. |
|
public static Duration |
getWeek(Integer self)Same week duration as getWeeks(Integer). |
|
public static Duration |
getWeeks(Integer self)A Duration of self * 7 days. |
|
public static DatumDependentDuration |
getYear(Integer self)Same year duration as getYears(Integer). |
|
public static DatumDependentDuration |
getYears(Integer self)A DatumDependentDuration whose year component is self. |
|
public static Date |
minus(Date date, BaseDuration duration)Subtracts each component of duration from date.
|
|
public static TimeDuration |
minus(Date lhs, Date rhs)Returns lhs - rhs as a TimeDuration. |
|
public static Date |
plus(Date date, BaseDuration duration)Adds duration to date by calendar field. |
Same day duration as getDays(Integer).
self - the number of days A Duration of self days.
self - the number of daysSame hour duration as getHours(Integer).
self - the number of hours A TimeDuration of self hours.
self - the number of hoursSame millisecond duration as getMilliseconds(Integer).
self - the number of milliseconds A TimeDuration of self milliseconds.
self - the number of millisecondsSame minute duration as getMinutes(Integer).
self - the number of minutes A TimeDuration of self minutes.
self - the number of minutesSame month duration as getMonths(Integer).
self - the number of months A DatumDependentDuration whose month component is self.
self - the number of monthsSame second duration as getSeconds(Integer).
self - the number of seconds A TimeDuration of self seconds.
self - the number of secondsSame week duration as getWeeks(Integer).
self - the number of weeks A Duration of self * 7 days.
self - the number of weeksSame year duration as getYears(Integer).
self - the number of years A DatumDependentDuration whose year component is self.
self - the number of years Subtracts each component of duration from date.
Hours, minutes, seconds, and milliseconds move the time of day.
date - the starting dateduration - the amount to subtract Returns lhs - rhs as a TimeDuration. The millisecond
difference is split into days, hours, minutes, seconds, and milliseconds
by integer division.
lhs - the later date when the result is positiverhs - the date subtracted from lhs Adds duration to date by calendar field.
date - the starting dateduration - the amount to add