Package com.twelvemonkeys.lang
Class DateUtil
java.lang.Object
com.twelvemonkeys.lang.DateUtil
A utility class with useful date manipulation methods and constants.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/lang/DateUtil.java#1 $
- Author:
- Harald Kuhr
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
One calendar year: 365.2425 days (31556952000 milliseconds).static final long
One day: 24 hours (86 400 000 milliseconds).static final long
One hour: 60 minutes (3 600 000 milliseconds).static final long
One minute: 60 seconds (60 000 milliseconds).static final long
One second: 1000 milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic long
Gets the current time, rounded down to the closest day.static long
Gets the current time, rounded down to the closest hour.static long
Gets the current time, rounded down to the closest minute.static long
Gets the current time, rounded down to the closest second.static long
delta
(long pStart) Returns the time between the given start time and now (as defined bySystem.currentTimeMillis()
).static long
Returns the time between the given start time and now (as defined bySystem.currentTimeMillis()
).static long
roundToDay
(long pTime) Rounds the given time down to the closest day, using the default timezone.static long
roundToDay
(long pTime, TimeZone pTimeZone) Rounds the given time down to the closest day, using the given timezone.static long
roundToHour
(long pTime) Rounds the given time down to the closest hour, using the default timezone.static long
roundToHour
(long pTime, TimeZone pTimeZone) Rounds the given time down to the closest hour, using the given timezone.static long
roundToMinute
(long pTime) Rounds the given time down to the closest minute.static long
roundToSecond
(long pTime) Rounds the given time down to the closest second.
-
Field Details
-
SECOND
public static final long SECONDOne second: 1000 milliseconds.- See Also:
-
MINUTE
public static final long MINUTEOne minute: 60 seconds (60 000 milliseconds).- See Also:
-
HOUR
public static final long HOUROne hour: 60 minutes (3 600 000 milliseconds). 60 minutes = 3 600 seconds = 3 600 000 milliseconds- See Also:
-
DAY
public static final long DAYOne day: 24 hours (86 400 000 milliseconds). 24 hours = 1 440 minutes = 86 400 seconds = 86 400 000 milliseconds.- See Also:
-
CALENDAR_YEAR
public static final long CALENDAR_YEAROne calendar year: 365.2425 days (31556952000 milliseconds). 365.2425 days = 8765.82 hours = 525949.2 minutes = 31556952 seconds = 31556952000 milliseconds.- See Also:
-
-
Method Details
-
delta
public static long delta(long pStart) Returns the time between the given start time and now (as defined bySystem.currentTimeMillis()
).- Parameters:
pStart
- the start time- Returns:
- the time between the given start time and now.
-
delta
Returns the time between the given start time and now (as defined bySystem.currentTimeMillis()
).- Parameters:
pStart
- the start time- Returns:
- the time between the given start time and now.
-
currentTimeSecond
public static long currentTimeSecond()Gets the current time, rounded down to the closest second. Equivalent to invokingroundToSecond(System.currentTimeMillis())
.- Returns:
- the current time, rounded to the closest second.
-
currentTimeMinute
public static long currentTimeMinute()Gets the current time, rounded down to the closest minute. Equivalent to invokingroundToMinute(System.currentTimeMillis())
.- Returns:
- the current time, rounded to the closest minute.
-
currentTimeHour
public static long currentTimeHour()Gets the current time, rounded down to the closest hour. Equivalent to invokingroundToHour(System.currentTimeMillis())
.- Returns:
- the current time, rounded to the closest hour.
-
currentTimeDay
public static long currentTimeDay()Gets the current time, rounded down to the closest day. Equivalent to invokingroundToDay(System.currentTimeMillis())
.- Returns:
- the current time, rounded to the closest day.
-
roundToSecond
public static long roundToSecond(long pTime) Rounds the given time down to the closest second.- Parameters:
pTime
- time- Returns:
- the time rounded to the closest second.
-
roundToMinute
public static long roundToMinute(long pTime) Rounds the given time down to the closest minute.- Parameters:
pTime
- time- Returns:
- the time rounded to the closest minute.
-
roundToHour
public static long roundToHour(long pTime) Rounds the given time down to the closest hour, using the default timezone.- Parameters:
pTime
- time- Returns:
- the time rounded to the closest hour.
-
roundToHour
Rounds the given time down to the closest hour, using the given timezone.- Parameters:
pTime
- timepTimeZone
- the timezone to use when rounding- Returns:
- the time rounded to the closest hour.
-
roundToDay
public static long roundToDay(long pTime) Rounds the given time down to the closest day, using the default timezone.- Parameters:
pTime
- time- Returns:
- the time rounded to the closest day.
-
roundToDay
Rounds the given time down to the closest day, using the given timezone.- Parameters:
pTime
- timepTimeZone
- the timezone to use when rounding- Returns:
- the time rounded to the closest day.
-