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