public class TimestampUtils
extends java.lang.Object
Constructor and Description |
---|
TimestampUtils(boolean usesDouble,
Provider<java.util.TimeZone> timeZoneProvider) |
Modifier and Type | Method and Description |
---|---|
java.sql.Date |
convertToDate(long millis,
java.util.TimeZone tz)
Extracts the date part from a timestamp.
|
java.sql.Time |
convertToTime(long millis,
java.util.TimeZone tz)
Extracts the time part from a timestamp.
|
java.util.Calendar |
getSharedCalendar(java.util.TimeZone timeZone)
Get a shared calendar, applying the supplied time zone or the default time zone if null.
|
boolean |
hasFastDefaultTimeZone() |
static java.util.TimeZone |
parseBackendTimeZone(java.lang.String timeZone)
Converts backend's TimeZone parameter to java format.
|
java.lang.String |
timeToString(java.util.Date time,
boolean withTimeZone)
Returns the given time value as String matching what the current postgresql server would send
in text mode.
|
void |
toBinDate(java.util.TimeZone tz,
byte[] bytes,
java.sql.Date value)
Converts the SQL Date to binary representation for
Oid.DATE . |
java.sql.Date |
toDate(java.util.Calendar cal,
java.lang.String s) |
java.sql.Date |
toDateBin(java.util.TimeZone tz,
byte[] bytes)
Returns the SQL Date object matching the given bytes with
Oid.DATE . |
java.time.LocalDateTime |
toLocalDateTime(java.lang.String s)
Parse a string and return a LocalDateTime representing its value.
|
java.time.LocalDateTime |
toLocalDateTimeBin(byte[] bytes)
Returns the local date time object matching the given bytes with
Oid.TIMESTAMP or
Oid.TIMESTAMPTZ . |
java.time.LocalTime |
toLocalTime(java.lang.String s)
Parse a string and return a LocalTime representing its value.
|
java.time.LocalTime |
toLocalTimeBin(byte[] bytes)
Returns the SQL Time object matching the given bytes with
Oid.TIME . |
java.time.OffsetDateTime |
toOffsetDateTime(java.lang.String s)
Parse a string and return a LocalDateTime representing its value.
|
java.time.OffsetDateTime |
toOffsetDateTime(java.sql.Time t)
Returns the offset date time object matching the given bytes with Oid#TIMETZ.
|
java.time.OffsetDateTime |
toOffsetDateTimeBin(byte[] bytes)
Returns the offset date time object matching the given bytes with Oid#TIMESTAMPTZ.
|
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Date x) |
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Date x,
boolean withTimeZone) |
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Time x) |
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Time x,
boolean withTimeZone) |
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Timestamp x) |
java.lang.String |
toString(java.util.Calendar cal,
java.sql.Timestamp x,
boolean withTimeZone) |
java.lang.String |
toString(java.time.LocalDate localDate) |
java.lang.String |
toString(java.time.LocalDateTime localDateTime)
Formats
LocalDateTime to be sent to the backend, thus it adds time zone. |
java.lang.String |
toString(java.time.LocalTime localTime) |
java.lang.String |
toString(java.time.OffsetDateTime offsetDateTime) |
java.sql.Time |
toTime(java.util.Calendar cal,
java.lang.String s) |
java.sql.Time |
toTimeBin(java.util.TimeZone tz,
byte[] bytes)
Returns the SQL Time object matching the given bytes with
Oid.TIME or
Oid.TIMETZ . |
java.sql.Timestamp |
toTimestamp(java.util.Calendar cal,
java.lang.String s)
Parse a string and return a timestamp representing its value.
|
java.sql.Timestamp |
toTimestampBin(java.util.TimeZone tz,
byte[] bytes,
boolean timestamptz)
Returns the SQL Timestamp object matching the given bytes with
Oid.TIMESTAMP or
Oid.TIMESTAMPTZ . |
public TimestampUtils(boolean usesDouble, Provider<java.util.TimeZone> timeZoneProvider)
public java.sql.Timestamp toTimestamp(java.util.Calendar cal, java.lang.String s) throws java.sql.SQLException
cal
- calendar to be used to parse the input strings
- The ISO formated date string to parse.java.sql.SQLException
- if there is a problem parsing s.public java.time.LocalTime toLocalTime(java.lang.String s) throws java.sql.SQLException
s
- The ISO formated time string to parse.java.sql.SQLException
- if there is a problem parsing s.public java.time.LocalDateTime toLocalDateTime(java.lang.String s) throws java.sql.SQLException
s
- The ISO formated date string to parse.java.sql.SQLException
- if there is a problem parsing s.public java.time.OffsetDateTime toOffsetDateTime(java.lang.String s) throws java.sql.SQLException
s
- The ISO formated date string to parse.java.sql.SQLException
- if there is a problem parsing s.public java.time.OffsetDateTime toOffsetDateTime(java.sql.Time t)
t
- the time valuepublic java.time.OffsetDateTime toOffsetDateTimeBin(byte[] bytes) throws PSQLException
bytes
- The binary encoded local date time value.PSQLException
- If binary format could not be parsed.public java.sql.Time toTime(java.util.Calendar cal, java.lang.String s) throws java.sql.SQLException
java.sql.SQLException
public java.sql.Date toDate(java.util.Calendar cal, java.lang.String s) throws java.sql.SQLException
java.sql.SQLException
public java.util.Calendar getSharedCalendar(java.util.TimeZone timeZone)
timeZone
- time zone to be set for the calendarpublic java.lang.String toString(java.util.Calendar cal, java.sql.Timestamp x)
public java.lang.String toString(java.util.Calendar cal, java.sql.Timestamp x, boolean withTimeZone)
public java.lang.String toString(java.util.Calendar cal, java.sql.Date x)
public java.lang.String toString(java.util.Calendar cal, java.sql.Date x, boolean withTimeZone)
public java.lang.String toString(java.util.Calendar cal, java.sql.Time x)
public java.lang.String toString(java.util.Calendar cal, java.sql.Time x, boolean withTimeZone)
public java.lang.String toString(java.time.LocalDate localDate)
public java.lang.String toString(java.time.LocalTime localTime)
public java.lang.String toString(java.time.OffsetDateTime offsetDateTime)
public java.lang.String toString(java.time.LocalDateTime localDateTime)
LocalDateTime
to be sent to the backend, thus it adds time zone.
Do not use this method in ResultSet.getString(int)
localDateTime
- The local date to format as a Stringpublic java.sql.Date toDateBin(java.util.TimeZone tz, byte[] bytes) throws PSQLException
Oid.DATE
.tz
- The timezone used.bytes
- The binary encoded date value.PSQLException
- If binary format could not be parsed.public boolean hasFastDefaultTimeZone()
public java.sql.Time toTimeBin(java.util.TimeZone tz, byte[] bytes) throws PSQLException
Oid.TIME
or
Oid.TIMETZ
.tz
- The timezone used when received data is Oid.TIME
, ignored if data already
contains Oid.TIMETZ
.bytes
- The binary encoded time value.PSQLException
- If binary format could not be parsed.public java.time.LocalTime toLocalTimeBin(byte[] bytes) throws PSQLException
Oid.TIME
.bytes
- The binary encoded time value.PSQLException
- If binary format could not be parsed.public java.sql.Timestamp toTimestampBin(java.util.TimeZone tz, byte[] bytes, boolean timestamptz) throws PSQLException
Oid.TIMESTAMP
or
Oid.TIMESTAMPTZ
.tz
- The timezone used when received data is Oid.TIMESTAMP
, ignored if data
already contains Oid.TIMESTAMPTZ
.bytes
- The binary encoded timestamp value.timestamptz
- True if the binary is in GMT.PSQLException
- If binary format could not be parsed.public java.time.LocalDateTime toLocalDateTimeBin(byte[] bytes) throws PSQLException
Oid.TIMESTAMP
or
Oid.TIMESTAMPTZ
.bytes
- The binary encoded local date time value.PSQLException
- If binary format could not be parsed.public java.sql.Date convertToDate(long millis, java.util.TimeZone tz)
millis
- The timestamp from which to extract the date.tz
- The time zone of the date.public java.sql.Time convertToTime(long millis, java.util.TimeZone tz)
millis
- The timestamp from which to extract the time.tz
- timezone to use.public java.lang.String timeToString(java.util.Date time, boolean withTimeZone)
time
- time valuewithTimeZone
- whether timezone should be addedpublic void toBinDate(java.util.TimeZone tz, byte[] bytes, java.sql.Date value) throws PSQLException
Oid.DATE
.tz
- The timezone used.bytes
- The binary encoded date value.value
- valuePSQLException
- If binary format could not be parsed.public static java.util.TimeZone parseBackendTimeZone(java.lang.String timeZone)
timeZone
- time zone to useCopyright © 2021 PostgreSQL Global Development Group. All rights reserved.