Package groovy.time
Class TimeCategory
java.lang.Object
groovy.time.TimeCategory
Apply a number of methods to allow convenient Date/Time manipulation,such as:
use (groovy.time.TimeCategory) {
// application on numbers:
println 1.minute.from.now
println 10.hours.ago
// application on dates
def someDate = new Date()
println someDate - 3.months
}
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DurationAlias forgetDays(Integer).static DurationGets the daylight savings offset for the supplied duration interpreted as a date.static DurationgetDaylightSavingsOffset(Date self) Get the DST offset (if any) for the default locale and the given date.static DurationReturns a day-based duration for the supplied number of days.static TimeDurationAlias forgetHours(Integer).static TimeDurationReturns an hour-based duration for the supplied number of hours.static TimeDurationgetMillisecond(Integer self) Alias forgetMilliseconds(Integer).static TimeDurationgetMilliseconds(Integer self) Returns a millisecond-based duration for the supplied number of milliseconds.static TimeDurationAlias forgetMinutes(Integer).static TimeDurationgetMinutes(Integer self) Returns a minute-based duration for the supplied number of minutes.static DatumDependentDurationAlias forgetMonths(Integer).static DatumDependentDurationReturns a month-based duration for the supplied number of months.static DurationgetRelativeDaylightSavingsOffset(Date self, Date other) Return a Duration representing the DST difference (if any) between two dates.static TimeDurationAlias forgetSeconds(Integer).static TimeDurationgetSeconds(Integer self) Returns a second-based duration for the supplied number of seconds.static TimeZonegetTimeZone(Date self) Deprecated.static DurationAlias forgetWeeks(Integer).static DurationReturns a week-based duration for the supplied number of weeks.static DatumDependentDurationAlias forgetYears(Integer).static DatumDependentDurationReturns a year-based duration for the supplied number of years.static Dateminus(Date date, BaseDuration duration) Subtracts a duration from a date.static TimeDurationSubtract one date from the other.static Dateplus(Date date, BaseDuration duration) Adds a duration to a date.
-
Constructor Details
-
TimeCategory
public TimeCategory()
-
-
Method Details
-
plus
Adds a duration to a date.- Parameters:
date- the base dateduration- the duration to add- Returns:
- the adjusted date
-
minus
Subtracts a duration from a date.- Parameters:
date- the base dateduration- the duration to subtract- Returns:
- the adjusted date
-
getTimeZone
Deprecated.Retrieves the default TimeZone for a date by using the default Locale settings. Recommended that you useTimeZone.getDefault()instead.- Parameters:
self- a Date- Returns:
- the TimeZone
-
getDaylightSavingsOffset
Get the DST offset (if any) for the default locale and the given date.- Parameters:
self- a Date- Returns:
- the DST offset as a Duration.
-
getDaylightSavingsOffset
Gets the daylight savings offset for the supplied duration interpreted as a date.- Parameters:
self- the duration to inspect- Returns:
- the DST offset as a duration
-
getRelativeDaylightSavingsOffset
Return a Duration representing the DST difference (if any) between two dates. i.e. if one date is before the DST changeover, and the other date is after, the resulting duration will represent the DST offset.- Parameters:
self- a Dateother- another Date- Returns:
- a Duration
-
minus
Subtract one date from the other.- Parameters:
lhs- a Daterhs- another Date- Returns:
- a Duration
-
getMonths
Returns a month-based duration for the supplied number of months.- Parameters:
self- the number of months- Returns:
- the corresponding duration
-
getMonth
Alias forgetMonths(Integer).- Parameters:
self- the number of months- Returns:
- the corresponding duration
-
getYears
Returns a year-based duration for the supplied number of years.- Parameters:
self- the number of years- Returns:
- the corresponding duration
-
getYear
Alias forgetYears(Integer).- Parameters:
self- the number of years- Returns:
- the corresponding duration
-
getWeeks
Returns a week-based duration for the supplied number of weeks.- Parameters:
self- the number of weeks- Returns:
- the corresponding duration
-
getWeek
Alias forgetWeeks(Integer).- Parameters:
self- the number of weeks- Returns:
- the corresponding duration
-
getDays
Returns a day-based duration for the supplied number of days.- Parameters:
self- the number of days- Returns:
- the corresponding duration
-
getDay
Alias forgetDays(Integer).- Parameters:
self- the number of days- Returns:
- the corresponding duration
-
getHours
Returns an hour-based duration for the supplied number of hours.- Parameters:
self- the number of hours- Returns:
- the corresponding duration
-
getHour
Alias forgetHours(Integer).- Parameters:
self- the number of hours- Returns:
- the corresponding duration
-
getMinutes
Returns a minute-based duration for the supplied number of minutes.- Parameters:
self- the number of minutes- Returns:
- the corresponding duration
-
getMinute
Alias forgetMinutes(Integer).- Parameters:
self- the number of minutes- Returns:
- the corresponding duration
-
getSeconds
Returns a second-based duration for the supplied number of seconds.- Parameters:
self- the number of seconds- Returns:
- the corresponding duration
-
getSecond
Alias forgetSeconds(Integer).- Parameters:
self- the number of seconds- Returns:
- the corresponding duration
-
getMilliseconds
Returns a millisecond-based duration for the supplied number of milliseconds.- Parameters:
self- the number of milliseconds- Returns:
- the corresponding duration
-
getMillisecond
Alias forgetMilliseconds(Integer).- Parameters:
self- the number of milliseconds- Returns:
- the corresponding duration
-