Truncate to microseconds
Obviously, we cannot compress the resolution of nanoseconds Instant
to the resolution of microseconds for MySQL data types DateTime
and Timestamp
.
I believe that the JDBC driver is built to ignore nanoseconds at reception Instant
, reducing the value to microseconds. I suggest you try the experiment and maybe study the source code of your driver, which corresponds to JDBC 4.2 and later.
Instant instant = Instant.now().with( ChronoField.NANO_OF_SECOND , 123_456_789L ) ; //Set the fractional second to a spefic number of nanoseconds.
myPreparedStatement.setObject( … , instant ) ;
... and ...
Instant instant2 = myResultSet.getObject( … , Instant.class ) ;
Then compare.
Boolean result = instant.equals( instant2 ) ;
System.out.println( "instant: " + instant + " equals instant2: = " + instant2 + " is: " + result ) ;
, , . , -, . .
Instant instant = Instant().now().truncatedTo( ChronoUnit.MICROSECONDS ) ;
, - . , , .
- , , count-from-epoch.
-, . , MySQL Postgres, .
, 1970-01-01T00: 00Z, , Instant
: .
. .
/ / Instant
. 64- long
; BigDecimal
BigInteger
. , 32- . 64- java.time.Instant
.
long seconds = instant.getEpochSecond() ;
long nanos = instant.getNano() ;
... ...
Instant instant = Instant.ofEpochSecond( seconds , nanos ) ;
, , " ".