类 TimeUtil


  • public class TimeUtil
    extends Object
    Time zone conversion routines and other time related methods
    • 字段详细资料

      • DEFAULT_DATE

        public static final java.time.LocalDate DEFAULT_DATE
      • DEFAULT_TIME

        public static final java.time.LocalTime DEFAULT_TIME
      • DATE_FORMATTER

        public static final java.time.format.DateTimeFormatter DATE_FORMATTER
      • TIME_FORMATTER_NO_FRACT_NO_OFFSET

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_NO_OFFSET
      • TIME_FORMATTER_WITH_NANOS_NO_OFFSET

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_NO_OFFSET
      • TIME_FORMATTER_NO_FRACT_WITH_OFFSET

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_WITH_OFFSET
      • TIME_FORMATTER_WITH_NANOS_WITH_OFFSET

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_WITH_OFFSET
      • TIME_FORMATTER_WITH_OPTIONAL_MICROS

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_OPTIONAL_MICROS
      • DATETIME_FORMATTER_NO_FRACT_NO_OFFSET

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_NO_OFFSET
      • DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET
      • DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET
      • DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET
      • DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET
      • DATETIME_FORMATTER_WITH_OPTIONAL_MICROS

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_OPTIONAL_MICROS
      • DATE_LITERAL_WITH_DELIMITERS

        public static final Pattern DATE_LITERAL_WITH_DELIMITERS
      • DATE_LITERAL_NO_DELIMITERS

        public static final Pattern DATE_LITERAL_NO_DELIMITERS
      • TIME_LITERAL_WITH_DELIMITERS

        public static final Pattern TIME_LITERAL_WITH_DELIMITERS
      • TIME_LITERAL_SHORT6

        public static final Pattern TIME_LITERAL_SHORT6
      • TIME_LITERAL_SHORT4

        public static final Pattern TIME_LITERAL_SHORT4
      • TIME_LITERAL_SHORT2

        public static final Pattern TIME_LITERAL_SHORT2
      • DATETIME_LITERAL_WITH_DELIMITERS

        public static final Pattern DATETIME_LITERAL_WITH_DELIMITERS
      • DATETIME_LITERAL_SHORT14

        public static final Pattern DATETIME_LITERAL_SHORT14
      • DATETIME_LITERAL_SHORT12

        public static final Pattern DATETIME_LITERAL_SHORT12
      • DURATION_LITERAL_WITH_DAYS

        public static final Pattern DURATION_LITERAL_WITH_DAYS
      • DURATION_LITERAL_NO_DAYS

        public static final Pattern DURATION_LITERAL_NO_DAYS
      • systemNanoTimeMethod

        protected static final Method systemNanoTimeMethod
    • 构造器详细资料

      • TimeUtil

        public TimeUtil()
    • 方法详细资料

      • nanoTimeAvailable

        public static boolean nanoTimeAvailable()
      • getCurrentTimeNanosOrMillis

        public static long getCurrentTimeNanosOrMillis()
      • getCanonicalTimeZone

        public static String getCanonicalTimeZone​(String timezoneStr,
                                                  ExceptionInterceptor exceptionInterceptor)
        Returns the 'official' Java timezone name for the given timezone
        参数:
        timezoneStr - the 'common' timezone name
        exceptionInterceptor - exception interceptor
        返回:
        the Java timezone name for the given timezone
      • adjustNanosPrecision

        public static Timestamp adjustNanosPrecision​(Timestamp ts,
                                                     int fsp,
                                                     boolean serverRoundFracSecs)
        Return a new Timestamp object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.
        参数:
        ts - an original Timestamp object, not modified by this method
        fsp - value in the range from 0 to 6 specifying fractional seconds precision
        serverRoundFracSecs - Flag indicating whether rounding or truncation occurs on server when inserting a TIME, DATE, or TIMESTAMP value with a fractional seconds part into a column having the same type but fewer fractional digits: true means rounding, false means truncation. The proper value should be detected by analyzing sql_mode server variable for TIME_TRUNCATE_FRACTIONAL presence.
        返回:
        A new Timestamp object cloned from the original one and then rounded or truncated according to required fsp value
      • adjustNanosPrecision

        public static java.time.LocalDateTime adjustNanosPrecision​(java.time.LocalDateTime x,
                                                                   int fsp,
                                                                   boolean serverRoundFracSecs)
        Return a new LocalDateTime object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.
        参数:
        x - an original LocalDateTime object, not modified by this method
        fsp - value in the range from 0 to 6 specifying fractional seconds precision
        serverRoundFracSecs - Flag indicating whether rounding or truncation occurs on server when inserting a TIME, DATE, or TIMESTAMP value with a fractional seconds part into a column having the same type but fewer fractional digits: true means rounding, false means truncation. The proper value should be detected by analyzing sql_mode server variable for TIME_TRUNCATE_FRACTIONAL presence.
        返回:
        A new LocalDateTime object cloned from the original one and then rounded or truncated according to required fsp value
      • adjustNanosPrecision

        public static java.time.LocalTime adjustNanosPrecision​(java.time.LocalTime x,
                                                               int fsp,
                                                               boolean serverRoundFracSecs)
      • adjustNanosPrecision

        public static java.time.Duration adjustNanosPrecision​(java.time.Duration x,
                                                              int fsp,
                                                              boolean serverRoundFracSecs)
      • formatNanos

        public static String formatNanos​(int nanos,
                                         int fsp)
        Return a string representation of a fractional seconds part. This method assumes that all Timestamp adjustments are already done before, thus no rounding is needed, only a proper "0" padding to be done.
        参数:
        nanos - fractional seconds value
        fsp - required fractional part length
        返回:
        fractional seconds part as a string
      • formatNanos

        public static String formatNanos​(int nanos,
                                         int fsp,
                                         boolean truncateTrailingZeros)
        Return a string representation of a fractional seconds part. This method assumes that all Timestamp adjustments are already done before, thus no rounding is needed, only a proper "0" padding to be done.
        参数:
        nanos - fractional seconds value
        fsp - required fractional part length
        truncateTrailingZeros - whether to remove trailing zero characters in a fractional part after formatting
        返回:
        fractional seconds part as a string
      • truncateFractionalSeconds

        public static Timestamp truncateFractionalSeconds​(Timestamp timestamp)
      • truncateFractionalSeconds

        public static Time truncateFractionalSeconds​(Time time)
      • hasFractionalSeconds

        public static Boolean hasFractionalSeconds​(Time t)
      • getSimpleDateFormat

        public static SimpleDateFormat getSimpleDateFormat​(SimpleDateFormat cachedSimpleDateFormat,
                                                           String pattern,
                                                           TimeZone tz)
        Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.

        Note: The SimpleDateFormat object returned by this method contains a default Calendar with an altered TimeZone. It's safe to cache it between this method calls because the Calendar object itself is not altered.

        参数:
        cachedSimpleDateFormat - existing SimpleDateFormat to use instead of creating a new one
        pattern - format pattern
        tz - TimeZone object replacing the default one
        返回:
        SimpleDateFormat object
      • getSimpleDateFormat

        public static SimpleDateFormat getSimpleDateFormat​(String pattern,
                                                           Calendar cal)
        Get SimpleDateFormat where a default Calendar is replaced with a clone of the provided one.

        Note: Don't cache the SimpleDateFormat object returned by this method. Other methods could rely on assumption that the cached SimpleDateFormat has a default Calendar and that it is safe to change only it's time zone (see getSimpleDateFormat(SimpleDateFormat, String, TimeZone).

        参数:
        pattern - format pattern
        cal - Calendar object which clone is replacing the default Calendar
        返回:
        SimpleDateFormat object
      • parseToDateTimeObject

        public static Object parseToDateTimeObject​(String s,
                                                   MysqlType targetMysqlType)
      • getDurationString

        public static String getDurationString​(java.time.Duration x)