Which one is recommended: Instant.now().toEpochMilli() or System.currentTimeMillis()

Both are fine. And neither is recommended except for a minority of purposes. What do you need milliseconds since the epoch for? In Java, we can have many different ways to get the current timestamp, For current timestamp just use Instant.now(). No need to convert to milliseconds. Many methods from the first years of Java, … Read more

Java date parsing with microsecond or nanosecond accuracy

tl;dr LocalDateTime.parse( // With resolution of nanoseconds, represent the idea of a date and time somewhere, unspecified. Does *not* represent a moment, is *not* a point on the timeline. To determine an actual moment, place this date+time into context of a time zone (apply a `ZoneId` to get a `ZonedDateTime`). “2015-05-09 00:10:23.999750900” // A `String` … Read more

Get milliseconds until midnight

Use a Calendar to compute it : Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long howMany = (c.getTimeInMillis()-System.currentTimeMillis());

H2 database string to timestamp

According to my test, with H2 version 1.3.170, the milliseconds are not actually zero, but 069: select * from test; ID DATE 1 2012-09-17 18:47:52.069 The same happens if you run: call parsedatetime(’17-09-2012 18:47:52.69′, ‘dd-MM-yyyy hh:mm:ss.SS’); If you add a zero then it works: call parsedatetime(’17-09-2012 18:47:52.690′, ‘dd-MM-yyyy hh:mm:ss.SS’); H2 internally uses java.text.SimpleDateFormat, so it … Read more