Home » Support » Forum » java.sql.Time field off by 30 minutes

java.sql.Time field off by 30 minutes


Hihi, I'm wondering if this is a bug.

I have a simple entity with java.sql.Time field.

On writing and readback, the field is found to be 30 minutes off. It is observed on objectdb explorer as well.

Timestamp works perfectly fine.

Ps. dont think its a UTC issue. My system is set at far off UTC+30min time.



Currently there is no known bug that may cause this. Maybe it is related to your specific system or Java configuration (possibly combined with ObjectDB).

Can you provide a simple runnable example to demonstrate this?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)




Thank you for the test case.

Here is a revised version that also prints the default time zone (and with some fixes and adjustments to the posting instructions):

import java.util.*;
import javax.persistence.*;

public class T707 {

    public static void main(String[] args) {
        EntityManagerFactory emf =
        EntityManager em = emf.createEntityManager();
        MyEntity e = new MyEntity();

        //()Refresh read back

        //()Read back all
        em.clear(); ///<<<clear local cache and read back new
        Query query = em.createQuery("SELECT e FROM MyEntity e");
        List resultList = query.getResultList();


    public static class MyEntity {
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        private long id;
        String myname = "Roger";
        java.sql.Time mytime =
            new java.sql.Time(System.currentTimeMillis());
        java.sql.Timestamp mytimestamp =
            new java.sql.Timestamp(System.currentTimeMillis());

        public String toString() {
            return "MyEntity{" + "id=" + id + ", myname=" + myname +
                ", mytime=" + mytime + ", mytimestamp=" + mytimestamp + '}';

I ran it on my computer and the output looks correct:

MyEntity{id=1, myname=Roger, mytime=21:33:15, mytimestamp=2012-03-07 21:33:15.291}
MyEntity{id=1, myname=Roger, mytime=21:33:15, mytimestamp=2012-03-07 21:33:15.291}
[MyEntity{id=1, myname=Roger, mytime=21:33:15, mytimestamp=2012-03-07 21:33:15.291}]

So as expected, this is probably related to specific settings. Maybe there is a problem when the time offset includes half a hour (e.g. UTC+05:30).

Could you please post the output that you get when you run the revised test?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Still the same :(... I am at UTC+8 :

MyEntity{id=1, myname=Roger, mytime=09:07:09, mytimestamp=2012-03-09 9:07:09.66}
MyEntity{id=1, myname=Roger, mytime=08:37:09, mytimestamp=2012-03-09 9:07:09.66}
[MyEntity{id=1, myname=Roger, mytime=08:37:09, mytimestamp=2012-03-09 9:07:09.66}]


Since the problem doesn't occur in my environment, exploring it is difficult and your help will be needed.

Here is another simple test (that doesn't use ObjectDB):

public class T707b {

    public static void main(String[] args) {
        java.sql.Time mytime1 =
            new java.sql.Time(System.currentTimeMillis());
        long time = mytime1.getTime();
        time = time % 86400000;
        java.sql.Time mytime2 = new java.sql.Time(0);

Could you please run it and publish the output?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

1) This is the output:


2) I switched to your location and it works fine. Seems like it doesnt work for my location/UTC.

Other locations with the same UTC+8 seems to work fine though.

Are u able to change the system timezone to my location and test??

I'm using windows 7 home premium and jdk6.


I see the problem on my machine now by running #6 with -Duser.timezone=Asia/Singapore:


But since this test doesn't use ObjectDB, it has to be something in how Java handles this specific time zone.

I found this report that may also be related:


As you wrote, the solution may be to use a different UTC+8 time zone.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login