In Linux I can find the current time in milliseconds using the command:
date +%s%N
but on FreeBSD I get only
[13:38 ]#date +%s%N
1299148740N
How can I get the time in milliseconds (or nanoseconds) in FreeBSD?
In Linux I can find the current time in milliseconds using the command:
date +%s%N
but on FreeBSD I get only
[13:38 ]#date +%s%N
1299148740N
How can I get the time in milliseconds (or nanoseconds) in FreeBSD?
Another way to get milliseconds is to use Python:
Outputs:
Note that python 2.x only returns 100ths of a second. May need to be tweaked slightly if your OS is using only Python 2.x to get more granularity.
Here's a one-liner for any recent Perl:
(modified from this answer to a similar question)
The BSD
date
command doesn't support milliseconds. If you want adate
with millisecond support, install the GNUcoreutils
package.I encountered this on OS X, whose
date
comes from BSD. The solution was tobrew install coreutils
andln -sf /usr/local/bin/gdate $HOME/bin
, and making sure that$HOME/bin
comes first inPATH
.Try using
tai64n
fromdaemontools
:Use
gettimeofday()
, for example: