public class TimestampUtils extends Object
Modifier and Type | Method and Description |
---|---|
Date |
convertToDate(long millis,
TimeZone tz)
Extracts the date part from a timestamp.
|
Time |
convertToTime(long millis,
TimeZone tz)
Extracts the time part from a timestamp.
|
Calendar |
getSharedCalendar(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(TimeZone tz,
byte[] bytes,
Date value)
Converts the SQL Date to binary representation for
Oid.DATE . |
Date |
toDate(Calendar cal,
String s) |
Date |
toDateBin(TimeZone tz,
byte[] bytes)
Returns the SQL Date object matching the given bytes with
Oid.DATE . |
LocalDateTime |
toLocalDateTime(String s)
Parse a string and return a LocalDateTime representing its value.
|
LocalDateTime |
toLocalDateTimeBin(TimeZone tz,
byte[] bytes)
Returns the local date time object matching the given bytes with
Oid.TIMESTAMP or
Oid.TIMESTAMPTZ . |
String |
toString(Calendar cal,
Date x) |
String |
toString(Calendar cal,
Date x,
boolean withTimeZone) |
String |
toString(Calendar cal,
Time x) |
String |
toString(Calendar cal,
Time x,
boolean withTimeZone) |
String |
toString(Calendar cal,
Timestamp x) |
String |
toString(Calendar cal,
Timestamp x,
boolean withTimeZone) |
String |
toString(LocalDate localDate) |
String |
toString(LocalDateTime localDateTime) |
String |
toString(LocalTime localTime) |
String |
toString(OffsetDateTime offsetDateTime) |
Time |
toTime(Calendar cal,
String s) |
Time |
toTimeBin(TimeZone tz,
byte[] bytes)
Returns the SQL Time object matching the given bytes with
Oid.TIME or
Oid.TIMETZ . |
Timestamp |
toTimestamp(Calendar cal,
String s)
Parse a string and return a timestamp representing its value.
|
Timestamp |
toTimestampBin(TimeZone tz,
byte[] bytes,
boolean timestamptz)
Returns the SQL Timestamp object matching the given bytes with
Oid.TIMESTAMP or
Oid.TIMESTAMPTZ . |
public Timestamp toTimestamp(Calendar cal, 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 LocalDateTime toLocalDateTime(String s) throws SQLException
s
- The ISO formated date string to parse.SQLException
- if there is a problem parsing s.public Time toTime(Calendar cal, String s) throws SQLException
SQLException
public Date toDate(Calendar cal, String s) throws SQLException
SQLException
public Calendar getSharedCalendar(TimeZone timeZone)
public String toString(OffsetDateTime offsetDateTime)
public String toString(LocalDateTime localDateTime)
public Date toDateBin(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(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 Timestamp toTimestampBin(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(TimeZone tz, 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, 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(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 © 2016 PostgreSQL Global Development Group. All rights reserved.