Package com.twelvemonkeys.lang
Class DateUtil
- java.lang.Object
-
- com.twelvemonkeys.lang.DateUtil
-
public final class DateUtil extends java.lang.Object
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
Fields Modifier and Type Field Description static long
CALENDAR_YEAR
One calendar year: 365.2425 days (31556952000 milliseconds).static long
DAY
One day: 24 hours (86 400 000 milliseconds).static long
HOUR
One hour: 60 minutes (3 600 000 milliseconds).static long
MINUTE
One minute: 60 seconds (60 000 milliseconds).static long
SECOND
One second: 1000 milliseconds.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
currentTimeDay()
Gets the current time, rounded down to the closest day.static long
currentTimeHour()
Gets the current time, rounded down to the closest hour.static long
currentTimeMinute()
Gets the current time, rounded down to the closest minute.static long
currentTimeSecond()
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
delta(java.util.Date pStart)
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, java.util.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, java.util.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 Detail
-
SECOND
public static final long SECOND
One second: 1000 milliseconds.- See Also:
- Constant Field Values
-
MINUTE
public static final long MINUTE
One minute: 60 seconds (60 000 milliseconds).- See Also:
- Constant Field Values
-
HOUR
public static final long HOUR
One hour: 60 minutes (3 600 000 milliseconds). 60 minutes = 3 600 seconds = 3 600 000 milliseconds- See Also:
- Constant Field Values
-
DAY
public static final long DAY
One day: 24 hours (86 400 000 milliseconds). 24 hours = 1 440 minutes = 86 400 seconds = 86 400 000 milliseconds.- See Also:
- Constant Field Values
-
CALENDAR_YEAR
public static final long CALENDAR_YEAR
One calendar year: 365.2425 days (31556952000 milliseconds). 365.2425 days = 8765.82 hours = 525949.2 minutes = 31556952 seconds = 31556952000 milliseconds.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public static long delta(java.util.Date 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.
-
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
public static long roundToHour(long pTime, java.util.TimeZone pTimeZone)
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
public static long roundToDay(long pTime, java.util.TimeZone pTimeZone)
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.
-
-