To get the current time with PostgreSQL, I have a simple query:
select now()::timestamptz
and an example output of that is
2022-06-15 23:43:41.418655 +00:00
However, when trying to work with this data in Java, this must be converted to Java's String
type, which under the hood seems to cast timestamptz
to text
or varchar
, which as you can see has different formatting:
2022-06-15 23:43:41.418655+00
(this is the same output with an explicit select now()::timestamptz::text
or select now()::timestamptz::varchar
; also, this output happens in a PostgreSQL command in a command line/visual console, not something weird with Java or a library itself)
Is my only option to strip off the last 3 characters and append " +00:00
" through Java, or is there a way I can modify my query to produce the desired results? (also I'm not sure if the 00
's are guaranteed)
Note: This project uses PostgresQL version 10.21