Inexplicable
As comments on your Question indicate, something very strange is afoot on your machine.
Your count of milliseconds since the epoch reference of 1970-01-01T00:00Z (the number 1,532,946,572,167) is being treated as zero. The debugger shows 1970-01-01T03:00:00.000+0300
. That 3 AM with an offset of +03:00 means the same moment as 1970-01-01T00:00Z, the epoch reference. In other words, a count of zero (0) milliseconds since 1970-01-01T00:00Z.
Here is simple code:
// Using terrible old legacy class `Date`.
Date x = new Date( System.currentTimeMillis() ) ;
System.out.println( x ) ;
boolean iJavaUtilsDate = x instanceof java.util.Date ;
System.out.println( "instanceof java.util.Date: " + iJavaUtilsDate ) ;
// Using modern *java.time* class `Instant`.
Instant y = Instant.now() ; // Capture the current moment in UTC.
System.out.println( y ) ;
Run that code live at IdeOne.com.
Tue Jul 31 04:18:58 GMT 2018
instanceof java.util.Date: true
2018-07-31T04:18:58.136Z
Suggestions
I suggest adding a call to Instant
as shown above to your problem code, out of curiosity.
Verify the actual class in use by calling instanceof
as shown in code above.
Try installing a new JDK. Perhaps there is some kind of corruption in your present JDK.
java.time
Also, java.util.Date
is a terrible class, part of the troublesome old date-time classes that were supplanted years ago by the modern java.time classes. There is no reason to be using this class nowadays.
If you must interoperate with old code not yet updated to java.time, you can convert back-and-forth by calling new conversion methods added to the old classes.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.*
classes.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.