sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

Getting a timestamp always results in 1969-12-31T16:00:02.019

Open PermissionError opened this issue 6 years ago • 3 comments

I have some code where I was to store the Timestamp now (using CURRENT_TIMESTAMP) into a row, then after some time check whether a day has passed or not. Currently, the date sets just fine, and I can read the correct value with the SQLite CLI. But when using my code to get the timestamp, it always returns 1969-12-31T16:00:02.019 no matter what I set it to.

No exceptions were thrown.

My code for reading the timestamp:

ResultSet rs = DB.prepareStatement("SELECT * FROM Cooldown WHERE UUID = \"" + uuid + "\"").executeQuery();
            if(!rs.next()){
                rs.close();
                //all System.out.println calls are debug lines that I used to find where the bug occurred
                System.out.println("-1");
                return false;
            }
            LocalDateTime last = rs.getTimestamp("LastReward").toLocalDateTime();
            LocalDateTime now = LocalDateTime.now();
            System.out.println("0");
            System.out.println(rs.getTimestamp("LastReward") + " " + last.toString() + " " + now.toString());

Output:

0
1969-12-31 16:00:02.019 1969-12-31T16:00:02.019 2019-02-13T20:29:49.238

PermissionError avatar Feb 14 '19 05:02 PermissionError

hi

BitCashMC avatar Feb 15 '19 22:02 BitCashMC

I can't seem to reproduce the problem. Can you provide more details (such as OS, sqlite-jdbc version, jdk/jre version and vendor) and a short self contained example? A short sample that creates a table, inserts a row with timestamp and reads it again should suffice.

There is however a deviation in your results that shouldn't be there. According to the reference there shouldn't be any miliseconds reported.

The format for CURRENT_TIMESTAMP is "YYYY-MM-DD HH:MM:SS"

This has been proven time and time again (See bug #88 ) to be true. This is where your code should break down. As rs.getTimestamp("LastReward") breaks down for a lack of those same milliseconds.

In neither case do you end up with an end of 1969 date however. The obvious 1970 epoch reference is in there, minus a few hours. So that definately isn't a coincidence.

In any case it would help to actually be able to reproduce your problem.

witmoca avatar Feb 19 '19 21:02 witmoca

Is this still happening on the latest version?

gotson avatar Jul 28 '22 09:07 gotson