Posts Tagged ‘unix time’

Java PostgreSQL timestamp to a Unix timestamp

Friday, March 16th, 2012

Suppose we have a timestamp in the database and would like to convert it to a Unix timestamp
There is a function called getTime() that will return the unix time.

long messageTime = rs.getTimestamp("startTime", Calendar.getInstance(TimeZone.getTimeZone("UTC"))).getTime();

PostgreSQL Getting a unix time from a timstamp with time zone

Friday, March 16th, 2012

If we have a timestamp with a timezone then getting the unix time from this is simple.
Note now() returns a timestamp with timezone so this query gets the current unix time