Package org.opends.server.core
Class TimeThread
java.lang.Object
org.opends.server.core.TimeThread
This class provides an application-wide timing service. It provides the ability to retrieve the current time in
various different formats and resolutions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Calendar
Retrieves aCalendar
containing the time at the last update.static Date
getDate()
Retrieves aDate
containing the time at the last update.static GeneralizedTime
Retrieves aGeneralizedTime
containing the time at the last update.static String
Retrieves a string containing a normalized representation of the current time in a generalized time format.static int
Retrieves an integer containing the time in HHmm format at the last update.static String
Retrieves a string containing the current time in the local time zone.static String
Retrieves a string containing the current time in UTC formatted according to RFC3339.static long
getTime()
Retrieves the time in milliseconds since the epoch at the last update.static String
getUserDefinedTime
(String formatString) Retrieves the current time formatted using the given format string.static String
Retrieves a string containing the current time in UTC.static void
removeUserDefinedFormatter
(String formatString) Removes the user-defined time formatter from this time thread so that it will no longer be maintained.static void
start
(ServerContext serverContext) Starts the time service if it has not already been started.static void
stop()
Stops the time service if it has not already been stopped.
-
Method Details
-
getCalendar
Retrieves aCalendar
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
Retrieves aDate
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
Retrieves aGeneralizedTime
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
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
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
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
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
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
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
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.
-