Class DateUtil

java.lang.Object
com.twelvemonkeys.lang.DateUtil

public final class DateUtil extends 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 $
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 by System.currentTimeMillis()).
    static long
    delta(Date pStart)
    Returns the time between the given start time and now (as defined by System.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SECOND

      public static final long SECOND
      One second: 1000 milliseconds.
      See Also:
    • MINUTE

      public static final long MINUTE
      One minute: 60 seconds (60 000 milliseconds).
      See Also:
    • 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:
    • 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:
    • 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:
  • 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 by System.currentTimeMillis()).
      Parameters:
      pStart - the start time
      Returns:
      the time between the given start time and now.
    • delta

      public static long delta(Date pStart)
      Returns the time between the given start time and now (as defined by System.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 invoking roundToSecond(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 invoking roundToMinute(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 invoking roundToHour(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 invoking roundToDay(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, TimeZone pTimeZone)
      Rounds the given time down to the closest hour, using the given timezone.
      Parameters:
      pTime - time
      pTimeZone - 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, TimeZone pTimeZone)
      Rounds the given time down to the closest day, using the given timezone.
      Parameters:
      pTime - time
      pTimeZone - the timezone to use when rounding
      Returns:
      the time rounded to the closest day.