Package org.opends.server.core
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 SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static CalendargetCalendar()Retrieves aCalendarcontaining the time at the last update.static DategetDate()Retrieves aDatecontaining the time at the last update.static GeneralizedTimegetGeneralizedTime()Retrieves aGeneralizedTimecontaining the time at the last update.static StringgetGeneralizedTimeString()Retrieves a string containing a normalized representation of the current time in a generalized time format.static intgetHourAndMinute()Retrieves an integer containing the time in HHmm format at the last update.static StringgetLocalTime()Retrieves a string containing the current time in the local time zone.static StringgetRfc3339UtcTime()Retrieves a string containing the current time in UTC formatted according to RFC3339.static longgetTime()Retrieves the time in milliseconds since the epoch at the last update.static StringgetUserDefinedTime(String formatString)Retrieves the current time formatted using the given format string.static StringgetUtcTime()Retrieves a string containing the current time in UTC.static voidremoveUserDefinedFormatter(String formatString)Removes the user-defined time formatter from this time thread so that it will no longer be maintained.static voidstart(ServerContext serverContext)Starts the time service if it has not already been started.static voidstop()Stops the time service if it has not already been stopped.
 
- 
- 
- 
Method Detail- 
getCalendarpublic static Calendar getCalendar() throws IllegalStateException Retrieves aCalendarcontaining the time at the last update.- Returns:
- A Calendarcontaining the time at the last update.
- Throws:
- IllegalStateException- If the time service has not been started.
 
 - 
getDatepublic static Date getDate() throws IllegalStateException Retrieves aDatecontaining the time at the last update.- Returns:
- A Datecontaining the time at the last update.
- Throws:
- IllegalStateException- If the time service has not been started.
 
 - 
getGeneralizedTimepublic static GeneralizedTime getGeneralizedTime() throws IllegalStateException Retrieves aGeneralizedTimecontaining the time at the last update.- Returns:
- A GeneralizedTimecontaining the time at the last update.
- Throws:
- IllegalStateException- If the time service has not been started.
 
 - 
getGeneralizedTimeStringpublic 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.
 
 - 
getUtcTimepublic 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.
 
 - 
getRfc3339UtcTimepublic 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.
 
 - 
getHourAndMinutepublic static int getHourAndMinute() throws IllegalStateExceptionRetrieves 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.
 
 - 
getLocalTimepublic 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.
 
 - 
getTimepublic 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.
 
 - 
getUserDefinedTimepublic 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.
 
 - 
removeUserDefinedFormatterpublic 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.
 
 - 
startpublic static void start(ServerContext serverContext) Starts the time service if it has not already been started.- Parameters:
- serverContext- The server context.
 
 - 
stoppublic static void stop() Stops the time service if it has not already been stopped.
 
- 
 
-