Class TimeThread

java.lang.Object
org.opends.server.core.TimeThread

public final class TimeThread extends Object
This class provides an application-wide timing service. It provides the ability to retrieve the current time in various different formats and resolutions.
  • Method Details

    • getCalendar

      public static Calendar getCalendar() throws IllegalStateException
      Retrieves a Calendar containing the time at the last update.
      Returns:
      A Calendar containing the time at the last update.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getDate

      public static Date getDate() throws IllegalStateException
      Retrieves a Date containing the time at the last update.
      Returns:
      A Date containing the time at the last update.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getGeneralizedTime

      public static GeneralizedTime getGeneralizedTime() throws IllegalStateException
      Retrieves a GeneralizedTime containing the time at the last update.
      Returns:
      A GeneralizedTime containing the time at the last update.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getGeneralizedTimeString

      public static String getGeneralizedTimeString() throws IllegalStateException
      Retrieves a string containing a normalized representation of the current time in a generalized time format. The timestamp will look like "20050101000000.000Z".
      Returns:
      A string containing a normalized representation of the current time in a generalized time format.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getUtcTime

      public static String getUtcTime() throws IllegalStateException
      Retrieves a string containing the current time in UTC. The timestamp will look like "20050101000000Z".
      Returns:
      A string containing the current time in UTC.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getRfc3339UtcTime

      public static String getRfc3339UtcTime() throws IllegalStateException
      Retrieves a string containing the current time in UTC formatted according to RFC3339. The timestamp will look like "2022-01-01T00:00:00.000Z".
      Returns:
      A string containing the current time in UTC formatted according to RFC3339.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getHourAndMinute

      public static int getHourAndMinute() throws IllegalStateException
      Retrieves an integer containing the time in HHmm format at the last update. It will be calculated as "(hourOfDay*100) + minuteOfHour".
      Returns:
      An integer containing the time in HHmm format at the last update.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getLocalTime

      public static String getLocalTime() throws IllegalStateException
      Retrieves a string containing the current time in the local time zone. The timestamp format will look like "01/Jan/2005:00:00:00 -0600".
      Returns:
      A string containing the current time in the local time zone.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getTime

      public static long getTime()
      Retrieves the time in milliseconds since the epoch at the last update.
      Returns:
      The time in milliseconds since the epoch at the last update.
      Throws:
      IllegalStateException - If the time service has not been started.
    • getUserDefinedTime

      public static String getUserDefinedTime(String formatString) throws IllegalArgumentException, IllegalStateException
      Retrieves the current time formatted using the given format string.

      The first time this method is used with a given format string, it will be used to create a formatter that will generate the time string. That formatter will then be put into a list so that it will be maintained automatically for future use.

      Parameters:
      formatString - The string that defines the format of the time string to retrieve.
      Returns:
      The formatted time string.
      Throws:
      IllegalArgumentException - If the provided format string is invalid.
      IllegalStateException - If the time service has not been started.
    • removeUserDefinedFormatter

      public static void removeUserDefinedFormatter(String formatString) throws IllegalStateException
      Removes the user-defined time formatter from this time thread so that it will no longer be maintained. This is a safe operation because if the same format string is used for multiple purposes then it will be added back the next time a time is requested with the given format.
      Parameters:
      formatString - The format string for the date formatter to remove.
      Throws:
      IllegalStateException - If the time service has not been started.
    • start

      public static void start(ServerContext serverContext)
      Starts the time service if it has not already been started.
      Parameters:
      serverContext - The server context.
    • stop

      public static void stop()
      Stops the time service if it has not already been stopped.