We can print the current time with the builtin printf
function, without needing to invoke an external command like date
, like this:
In bash
5, you can get microsecond precision from EPOCHREALTIME
. However, printf
itself has no way to access that directly, so you need to extract the microseconds yourself.
$ echo $EPOCHREALTIME; printf '%(%F:%T)T.%d\n' "$EPOCHSECONDS" "${EPOCHREALTIME#*.}"; echo $EPOCHREALTIME
1554006709.936990
2019-03-31:00:31:49.937048
1554006709.937083
This takes a little time, but the result appears to be accurate to about 0.05 milliseconds.