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 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longOne calendar year: 365.2425 days (31556952000 milliseconds).static final longOne day: 24 hours (86 400 000 milliseconds).static final longOne hour: 60 minutes (3 600 000 milliseconds).static final longOne minute: 60 seconds (60 000 milliseconds).static final longOne second: 1000 milliseconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longGets the current time, rounded down to the closest day.static longGets the current time, rounded down to the closest hour.static longGets the current time, rounded down to the closest minute.static longGets the current time, rounded down to the closest second.static longdelta(long pStart) Returns the time between the given start time and now (as defined bySystem.currentTimeMillis()).static longReturns the time between the given start time and now (as defined bySystem.currentTimeMillis()).static longroundToDay(long pTime) Rounds the given time down to the closest day, using the default timezone.static longroundToDay(long pTime, TimeZone pTimeZone) Rounds the given time down to the closest day, using the given timezone.static longroundToHour(long pTime) Rounds the given time down to the closest hour, using the default timezone.static longroundToHour(long pTime, TimeZone pTimeZone) Rounds the given time down to the closest hour, using the given timezone.static longroundToMinute(long pTime) Rounds the given time down to the closest minute.static longroundToSecond(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:
-
-
Constructor Details
-
DateUtil
private DateUtil()
-
-
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.
-