类 TimeUtil
- java.lang.Object
-
- com.mysql.cj.util.TimeUtil
-
public class TimeUtil extends Object
Timezone conversion routines and other time related methods
-
-
字段概要
字段 修饰符和类型 字段 说明 protected static MethodsystemNanoTimeMethod
-
构造器概要
构造器 构造器 说明 TimeUtil()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static TimestampadjustTimestampNanosPrecision(Timestamp ts, int fsp, boolean serverRoundFracSecs)Return a new Timestamp object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.static StringformatNanos(int nanos, int fsp)Return a string representation of a fractional seconds part.static StringformatNanos(int nanos, int fsp, boolean truncateTrailingZeros)Return a string representation of a fractional seconds part.static StringgetCanonicalTimezone(String timezoneStr, ExceptionInterceptor exceptionInterceptor)Returns the 'official' Java timezone name for the given timezonestatic longgetCurrentTimeNanosOrMillis()static StringgetDateTimePattern(String dt, boolean toTime)Used in prepared statementsstatic SimpleDateFormatgetSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, Calendar cal, TimeZone tz)static booleannanoTimeAvailable()static TimestamptruncateFractionalSeconds(Timestamp timestamp)
-
-
-
字段详细资料
-
systemNanoTimeMethod
protected static final Method systemNanoTimeMethod
-
-
方法详细资料
-
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 nameexceptionInterceptor- 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 methodfsp- value in the range from 0 to 6 specifying fractional seconds precisionserverRoundFracSecs- 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 valuefsp- 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 valuefsp- required fractional part lengthtruncateTrailingZeros- whether to remove trailing zero characters in a fractional part after formatting- 返回:
- fractional seconds part as a string
-
getSimpleDateFormat
public static SimpleDateFormat getSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, Calendar cal, TimeZone tz)
-
getDateTimePattern
public static final String getDateTimePattern(String dt, boolean toTime) throws IOException
Used in prepared statements- 参数:
dt- DateTime stringtoTime- true if get Time pattern- 返回:
- pattern
- 抛出:
IOException- if an error occurs
-
-