Re: How to insert "date" as timestamp

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: How to insert "date" as timestamp
Дата
Msg-id s34e27b0.054@gwmta.wicourts.gov
обсуждение исходный текст
Ответ на How to insert "date" as timestamp  (Aydın Toprak <aydin.toprak@intengo.com>)
Список pgsql-jdbc
Be careful about that with java.sql.Date.
To demonstrate the problem:

public class TestDate
{
    public static void main(String[] args)
        throws InterruptedException
    {
        java.util.Date utilDate = new java.util.Date(System.currentTimeMillis());
        java.sql.Date sqlDate1 = new java.sql.Date(utilDate.getTime());
        Thread.sleep(20L);
        utilDate = new java.util.Date(System.currentTimeMillis());
        java.sql.Date sqlDate2 = new java.sql.Date(utilDate.getTime());
        System.out.println(sqlDate1 + " equals " + sqlDate2 + " ?  " + sqlDate1.equals(sqlDate2));

        java.sql.Timestamp ts = new java.sql.Timestamp(sqlDate1.getTime());
        System.out.println(ts);
        ts = new java.sql.Timestamp(sqlDate2.getTime());
        System.out.println(ts);
    }
}

I get the following results:

2005-10-13 equals 2005-10-13 ?  false
2005-10-13 09:17:40.431
2005-10-13 09:17:40.461

Unfortunately, the burden is on the application programmer
to provide a ms value which is at midnight for the default
time zone for the JVM when using that constructor. I can't
understand that as a design choice, but that's the current
reality.

-Kevin


>>> Roland Walter <rwa@mosaic-ag.com> 10/13/05 4:10 AM >>>

The conversion works as the following, i. e.:

java.util.Date date = new java.util.Date(System.currentTimeMillis());
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());

It is the same for the conversion to java.sql.Date.


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: How to insert "date" as timestamp
Следующее
От: Roland Walter
Дата:
Сообщение: Re: How to insert "date" as timestamp