类 TimeUtil


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

      • 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
      • adjustTimestampNanosPrecision

        public static Timestamp adjustTimestampNanosPrecision​(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 original ones and then rounded or truncated according to required fsp value
      • 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)
      • getDateTimePattern

        public static final String getDateTimePattern​(String dt,
                                                      boolean toTime)
                                               throws IOException
        Used in prepared statements
        参数:
        dt - DateTime string
        toTime - true if get Time pattern
        返回:
        pattern
        抛出:
        IOException - if an error occurs