My data is in format:
2010-12-01 09:59:00.423
getDate in Java only returns the date portion. Is there a way to also extract the time?
You can use the LocalDate, LocalTime, LocalDateTime or OffsetDateTime (OffsetDateTime is an immutable representation of a date-time with an offset eg:the value "20th July 2017 at 10:45.24. 123456789 +04:00" can be stored in an OffsetDateTime). These classes comes in the java.
PostgreSQL stores the timestamptz in UTC value. When you insert a value into a timestamptz column, PostgreSQL converts the timestamptz value into a UTC value and stores the UTC value in the table.
Postgres DATE data type Postgres uses the DATE data type for storing different dates in YYYY-MM-DD format. It uses 4 bytes for storing a date value in a column. You can design a Postgres table with a DATE column and use the keyword DEFAULT CURRENT_DATE to use the current system date as the default value in this column.
The SQL DATE
type indeed only contains the date portion, not the time. But your column is apparently of TIMESTAMP
type, so to get the full timestamp, use ResultSet#getTimestamp()
instead.
Date date = resultSet.getTimestamp("columnname");
// ...
It returns java.sql.Timestamp
which is a subclass of java.util.Date
, so the upcast is safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With