public class TimeUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.time.format.DateTimeFormatter |
DATE_FORMATTER |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_NO_FRACT_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET |
protected static java.lang.reflect.Method |
systemNanoTimeMethod |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_NO_FRACT_NO_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_NO_FRACT_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_WITH_NANOS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_WITH_NANOS_WITH_OFFSET |
| Constructor and Description |
|---|
TimeUtil() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
static java.time.LocalTime |
adjustNanosPrecision(java.time.LocalTime x,
int fsp,
boolean serverRoundFracSecs) |
static java.sql.Timestamp |
adjustNanosPrecision(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 java.lang.Boolean |
hasFractionalSeconds(java.sql.Time t) |
static boolean |
nanoTimeAvailable() |
static java.sql.Time |
truncateFractionalSeconds(java.sql.Time time) |
static java.sql.Timestamp |
truncateFractionalSeconds(java.sql.Timestamp timestamp) |
public static final java.time.format.DateTimeFormatter DATE_FORMATTER
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_WITH_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET
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 adjustNanosPrecision(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.time.LocalDateTime adjustNanosPrecision(java.time.LocalDateTime x,
int fsp,
boolean serverRoundFracSecs)
x - an original LocalDateTime 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.time.LocalTime adjustNanosPrecision(java.time.LocalTime x,
int fsp,
boolean serverRoundFracSecs)
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.sql.Time truncateFractionalSeconds(java.sql.Time time)
public static java.lang.Boolean hasFractionalSeconds(java.sql.Time t)
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