Re: timestamps and java epochs

From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Laurette Cisneros <laurette(at)nextbus(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: timestamps and java epochs
Date: 2001-08-25 02:05:37
Message-ID: 20010825110537.O20830@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Sounds like a general pgsql question rather than a jdbc one... For
jdbc it doesn't matter, you just call ResultSet.getTimestamp() on
the field value. To get epoch time, you can just call getTime() on
the timestamp.

ie.

ResultSet rs = stmt.executeQuery("SELECT t1, t2 FROM xxxx");
Timestamp t1 = rs.getTimestamp(1);
Timestamp t2 = rs.getTimestamp(2);
long e1 = t1.getTime();
long e2 = t2.getTime();

Inside pgsql if you want epoch, just use...

SELECT EXTRACT(EPOCH FROM t1) FROM xxxx;

Tom.

On Fri, Aug 24, 2001 at 12:23:33PM -0700, Laurette Cisneros wrote:
>
> I have a table in which there are two fields that are timestamps.
>
> How do I parse these values back into epoch times? The
> docs say that the values may come back in one of four formats,
> how do I know which one I'll get? I can't seem to get JDBC to
> take the "set datestyle" command (it throws an SQLException).
>
> Even better: is there a database function I can use to turn these
> things into a unix epoch time?
>
> Thanks,
>
> Laurette
> Nextbus, Inc.
> www.nextbus.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Rene Pijlman 2001-08-25 20:56:12 Re: CVS compile problem
Previous Message Bruce Momjian 2001-08-25 01:43:59 CVS compile problem