public class TimeUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.reflect.Method |
systemNanoTimeMethod |
Constructor and Description |
---|
TimeUtil() |
Modifier and Type | Method and Description |
---|---|
static java.sql.Timestamp |
adjustTimestampNanosPrecision(java.sql.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 java.lang.String |
formatNanos(int nanos,
int fsp)
Return a string representation of a fractional seconds part.
|
static java.lang.String |
formatNanos(int nanos,
int fsp,
boolean truncateTrailingZeros)
Return a string representation of a fractional seconds part.
|
static java.lang.String |
getCanonicalTimezone(java.lang.String timezoneStr,
ExceptionInterceptor exceptionInterceptor)
Returns the 'official' Java timezone name for the given timezone
|
static long |
getCurrentTimeNanosOrMillis() |
static java.lang.String |
getDateTimePattern(java.lang.String dt,
boolean toTime)
Used in prepared statements
|
static java.text.SimpleDateFormat |
getSimpleDateFormat(java.text.SimpleDateFormat cachedSimpleDateFormat,
java.lang.String pattern,
java.util.TimeZone tz)
Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.
|
static java.text.SimpleDateFormat |
getSimpleDateFormat(java.lang.String pattern,
java.util.Calendar cal)
Get SimpleDateFormat where a default Calendar is replaced with the provided one.
|
static boolean |
nanoTimeAvailable() |
static java.sql.Timestamp |
truncateFractionalSeconds(java.sql.Timestamp timestamp) |
protected static final java.lang.reflect.Method systemNanoTimeMethod
public static boolean nanoTimeAvailable()
public static long getCurrentTimeNanosOrMillis()
public static java.lang.String getCanonicalTimezone(java.lang.String timezoneStr, ExceptionInterceptor exceptionInterceptor)
timezoneStr
- the 'common' timezone nameexceptionInterceptor
- exception interceptorpublic static java.sql.Timestamp adjustTimestampNanosPrecision(java.sql.Timestamp ts, int fsp, boolean serverRoundFracSecs)
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.public static java.lang.String formatNanos(int nanos, int fsp)
nanos
- fractional seconds valuefsp
- required fractional part lengthpublic static java.lang.String formatNanos(int nanos, int fsp, boolean truncateTrailingZeros)
nanos
- fractional seconds valuefsp
- required fractional part lengthtruncateTrailingZeros
- whether to remove trailing zero characters in a fractional part after formattingpublic static java.sql.Timestamp truncateFractionalSeconds(java.sql.Timestamp timestamp)
public static java.text.SimpleDateFormat getSimpleDateFormat(java.text.SimpleDateFormat cachedSimpleDateFormat, java.lang.String pattern, java.util.TimeZone tz)
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 onepattern
- format patterntz
- TimeZone
object replacing the default oneSimpleDateFormat
objectpublic static java.text.SimpleDateFormat getSimpleDateFormat(java.lang.String pattern, java.util.Calendar cal)
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 patterncal
- Calendar
object replacing the default oneSimpleDateFormat
objectpublic static final java.lang.String getDateTimePattern(java.lang.String dt, boolean toTime) throws java.io.IOException
dt
- DateTime stringtoTime
- true if get Time patternjava.io.IOException
- if an error occurs