パッケージ org.postgresql.jdbc
クラス TimestampUtils
java.lang.Object
org.postgresql.jdbc.TimestampUtils
Misc utils for handling time and date values.
-
コンストラクタの概要
コンストラクタ -
メソッドの概要
修飾子とタイプメソッド説明convertToDate
(long millis, @Nullable TimeZone tz) Extracts the date part from a timestamp.convertToTime
(long millis, TimeZone tz) Extracts the time part from a timestamp.getSharedCalendar
(@Nullable TimeZone timeZone) Get a shared calendar, applying the supplied time zone or the default time zone if null.boolean
static TimeZone
parseBackendTimeZone
(String timeZone) Converts backend's TimeZone parameter to java format.timeToString
(Date time, boolean withTimeZone) Returns the given time value as String matching what the current postgresql server would send in text mode.void
Converts the SQL Date to binary representation forOid.DATE
.@PolyNull Date
Returns the SQL Date object matching the given bytes withOid.DATE
.toLocalDateBin
(byte[] bytes) Returns the local date time object matching the given bytes withOid.DATE
orOid.TIMESTAMP
.@PolyNull LocalDateTime
toLocalDateTime
(@PolyNull String s) Parse a string and return a LocalDateTime representing its value.toLocalDateTimeBin
(byte[] bytes) Returns the local date time object matching the given bytes withOid.TIMESTAMP
orOid.TIMESTAMPTZ
.@PolyNull LocalTime
toLocalTime
(@PolyNull String s) Parse a string and return a LocalTime representing its value.toLocalTimeBin
(byte[] bytes) Returns the SQL Time object matching the given bytes withOid.TIME
.@PolyNull OffsetDateTime
toOffsetDateTime
(@PolyNull String s) Parse a string and return a OffsetDateTime representing its value.推奨されていません。was used internally, and not used anymoretoOffsetDateTimeBin
(byte[] bytes) Returns the offset date time object matching the given bytes with Oid#TIMESTAMPTZ.@PolyNull OffsetTime
toOffsetTime
(@PolyNull String s) Parse a string and return a OffsetTime representing its value.toOffsetTimeBin
(byte[] bytes) Returns the offset time object matching the given bytes with Oid#TIMETZ or Oid#TIME.toString
(LocalDateTime localDateTime) FormatsLocalDateTime
to be sent to the backend, thus it adds time zone.toString
(OffsetDateTime offsetDateTime) toString
(OffsetTime offsetTime) toStringOffsetDateTime
(byte[] value) Convertstimestamptz
to string taking client time zone (timeZoneProvider
) into account.toStringOffsetTimeBin
(byte[] value) Convertstimetz
to string taking client time zone (timeZoneProvider
) into account.@PolyNull Time
Returns the SQL Time object matching the given bytes withOid.TIME
orOid.TIMETZ
.@PolyNull Timestamp
toTimestamp
(@Nullable Calendar cal, @PolyNull String s) Parse a string and return a timestamp representing its value.toTimestampBin
(@Nullable TimeZone tz, byte[] bytes, boolean timestamptz) Returns the SQL Timestamp object matching the given bytes withOid.TIMESTAMP
orOid.TIMESTAMPTZ
.PostgreSQL does not store the time zone in the binary representation of timestamptz.PostgreSQL does not store the time zone in the binary representation of timetz.
-
コンストラクタの詳細
-
TimestampUtils
-
-
メソッドの詳細
-
toTimestamp
public @PolyNull Timestamp toTimestamp(@Nullable Calendar cal, @PolyNull String s) throws SQLException Parse a string and return a timestamp representing its value.- パラメータ:
cal
- calendar to be used to parse the input strings
- The ISO formated date string to parse.- 戻り値:
- null if s is null or a timestamp of the parsed string s.
- 例外:
SQLException
- if there is a problem parsing s.
-
toLocalTime
Parse a string and return a LocalTime representing its value.- パラメータ:
s
- The ISO formated time string to parse.- 戻り値:
- null if s is null or a LocalTime of the parsed string s.
- 例外:
SQLException
- if there is a problem parsing s.
-
toOffsetTimeBin
Returns the offset time object matching the given bytes with Oid#TIMETZ or Oid#TIME.- パラメータ:
bytes
- The binary encoded TIMETZ/TIME value.- 戻り値:
- The parsed offset time object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toOffsetTime
Parse a string and return a OffsetTime representing its value.- パラメータ:
s
- The ISO formated time string to parse.- 戻り値:
- null if s is null or a OffsetTime of the parsed string s.
- 例外:
SQLException
- if there is a problem parsing s.
-
toLocalDateTime
Parse a string and return a LocalDateTime representing its value.- パラメータ:
s
- The ISO formated date string to parse.- 戻り値:
- null if s is null or a LocalDateTime of the parsed string s.
- 例外:
SQLException
- if there is a problem parsing s.
-
toOffsetDateTime
推奨されていません。was used internally, and not used anymoreReturns the offset date time object matching the given bytes with Oid#TIMETZ. Not used internally anymore, function is here to retain compatibility with previous versions- パラメータ:
t
- the time value- 戻り値:
- the matching offset date time
-
toOffsetDateTime
Parse a string and return a OffsetDateTime representing its value.- パラメータ:
s
- The ISO formatted date string to parse.- 戻り値:
- null if s is null or a OffsetDateTime of the parsed string s.
- 例外:
SQLException
- if there is a problem parsing s.
-
toOffsetDateTimeBin
Returns the offset date time object matching the given bytes with Oid#TIMESTAMPTZ.- パラメータ:
bytes
- The binary encoded local date time value.- 戻り値:
- The parsed local date time object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toTime
- 例外:
SQLException
-
toDate
- 例外:
SQLException
-
toString
-
toString
-
toString
-
toString
-
toString
-
toString
-
toString
-
toString
-
toString
-
toStringOffsetTimeBin
Convertstimetz
to string taking client time zone (timeZoneProvider
) into account.- パラメータ:
value
- binary representation oftimetz
- 戻り値:
- string representation of
timetz
- 例外:
PSQLException
-
withClientOffsetSameInstant
PostgreSQL does not store the time zone in the binary representation of timetz. However, we want to preserve the output ofgetString()
in both binary and text formats So we try a client time zone when serializingOffsetTime
to string.- パラメータ:
input
- input offset time- 戻り値:
- adjusted offset time (it represents the same instant as the input one)
-
toString
-
toStringOffsetDateTime
Convertstimestamptz
to string taking client time zone (timeZoneProvider
) into account.- パラメータ:
value
- binary representation oftimestamptz
- 戻り値:
- string representation of
timestamptz
- 例外:
PSQLException
-
withClientOffsetSameInstant
PostgreSQL does not store the time zone in the binary representation of timestamptz. However, we want to preserve the output ofgetString()
in both binary and text formats So we try a client time zone when serializingOffsetDateTime
to string.- パラメータ:
input
- input offset date time- 戻り値:
- adjusted offset date time (it represents the same instant as the input one)
-
toString
FormatsLocalDateTime
to be sent to the backend, thus it adds time zone. Do not use this method inResultSet.getString(int)
- パラメータ:
localDateTime
- The local date to format as a String- 戻り値:
- The formatted local date
-
toDateBin
Returns the SQL Date object matching the given bytes withOid.DATE
.- パラメータ:
tz
- The timezone used.bytes
- The binary encoded date value.- 戻り値:
- The parsed date object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
hasFastDefaultTimeZone
public boolean hasFastDefaultTimeZone() -
toTimeBin
Returns the SQL Time object matching the given bytes withOid.TIME
orOid.TIMETZ
.- パラメータ:
tz
- The timezone used when received data isOid.TIME
, ignored if data already containsOid.TIMETZ
.bytes
- The binary encoded time value.- 戻り値:
- The parsed time object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toLocalTimeBin
Returns the SQL Time object matching the given bytes withOid.TIME
.- パラメータ:
bytes
- The binary encoded time value.- 戻り値:
- The parsed time object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toTimestampBin
public Timestamp toTimestampBin(@Nullable TimeZone tz, byte[] bytes, boolean timestamptz) throws PSQLException Returns the SQL Timestamp object matching the given bytes withOid.TIMESTAMP
orOid.TIMESTAMPTZ
.- パラメータ:
tz
- The timezone used when received data isOid.TIMESTAMP
, ignored if data already containsOid.TIMESTAMPTZ
.bytes
- The binary encoded timestamp value.timestamptz
- True if the binary is in GMT.- 戻り値:
- The parsed timestamp object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toLocalDateTimeBin
Returns the local date time object matching the given bytes withOid.TIMESTAMP
orOid.TIMESTAMPTZ
.- パラメータ:
bytes
- The binary encoded local date time value.- 戻り値:
- The parsed local date time object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
toLocalDateBin
Returns the local date time object matching the given bytes withOid.DATE
orOid.TIMESTAMP
.- パラメータ:
bytes
- The binary encoded local date value.- 戻り値:
- The parsed local date object.
- 例外:
PSQLException
- If binary format could not be parsed.
-
convertToDate
Extracts the date part from a timestamp.- パラメータ:
millis
- The timestamp from which to extract the date.tz
- The time zone of the date.- 戻り値:
- The extracted date.
-
convertToTime
Extracts the time part from a timestamp. This method ensures the date part of output timestamp looks like 1970-01-01 in given timezone.- パラメータ:
millis
- The timestamp from which to extract the time.tz
- timezone to use.- 戻り値:
- The extracted time.
-
timeToString
Returns the given time value as String matching what the current postgresql server would send in text mode.- パラメータ:
time
- time valuewithTimeZone
- whether timezone should be added- 戻り値:
- given time value as String
-
toBinDate
Converts the SQL Date to binary representation forOid.DATE
.- パラメータ:
tz
- The timezone used.bytes
- The binary encoded date value.value
- value- 例外:
PSQLException
- If binary format could not be parsed.
-
parseBackendTimeZone
Converts backend's TimeZone parameter to java format. Notable difference: backend's gmt-3 is GMT+03 in Java.- パラメータ:
timeZone
- time zone to use- 戻り値:
- java TimeZone
-