Class TimeThread

    • Method Detail

      • 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.
      • 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.
      • getGMTTime

        public static String getGMTTime()
                                 throws IllegalStateException
        Retrieves a string containing the current time in GMT. The timestamp will look like "20050101000000Z".
        Returns:
        A string containing the current time in GMT.
        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.
      • getNanoTime

        public static long getNanoTime()
                                throws IllegalStateException
        Retrieves the time in nanoseconds from the most precise available system timer. The value returned represents nanoseconds since some fixed but arbitrary time.
        Returns:
        The time in nanoseconds from some fixed but arbitrary time.
        Throws:
        IllegalStateException - If the time service has not been started.
      • getTime

        public static long getTime()
                            throws IllegalStateException
        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()
        Starts the time service if it has not already been started.
      • stop

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