Create Java DateTime Instant from microseconds

long timeMicros = 1_565_245_051_795_306L; Instant i = Instant.EPOCH.plus(timeMicros, ChronoUnit.MICROS); System.out.println(i); Output is: 2019-08-08T06:17:31.795306Z Edit: Rather than dividing and multiplying to convert microseconds to milliseconds and/or seconds I preferred to use the built-in support for microseconds. Also when explicitly adding them to the epoch feels a little hand-held. You already know how to convert Instant to … Read more

Convert java.time.Instant to java.sql.Timestamp without Zone offset

I changed my computer’s time zone to Europe/Bucharest for an experiment. This is UTC + 2 hours like your time zone. Now when I copy your code I get a result similar to yours: Instant now = Instant.now(); System.out.println(now); // prints 2017-03-14T06:16:32.621Z Timestamp current = Timestamp.from(now); System.out.println(current); // 2017-03-14 08:16:32.621 Output is given in comments. … Read more