Just tested this code on both my Windows (8) workstation and an AIX:
public static void main(String[] args) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(new Date()));
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(new Date()));
}
and got something similar to this as a result:
2013-10-07 12:53:26.000905
2013-10-07 12:53:26.000906
Can someone please explain me what are the last digits, if not microseconds?
Note: I interact with a DB2 database in which chronological data is stored using timed columns as TIMESTAMP with 6 digits AFTER the seconds i.e. microseconds (IMO). But all those "timestamps" are created by requesting the following query:
SELECT current timestamp as currenttimestamp FROM Table ( values (1)) temp
I wonder if, given the above results, I couldn't just use in my code new Date()
instead of selecting the current timestamp
from the database.
Thanks.
PS: I searched but found no relevant (answered) questions, like: Current time in microseconds in java or Get time with hour, minute, second, millisecond, microsecond
java.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 & Java 9. See Tutorial by Oracle.SimpleDateFormat
confusingly treats uppercaseS
as milliseconds no matter how many and how few, the modern counterpartDateTimeFormatter
treatsS
as fraction of second. So withDateTimeFormatter.ofPattern
you can meaningfully specify from 1 through 9S
and get the result you had expected.