How get the time in milliseconds in FreeBSD?
The BSD date
command doesn't support milliseconds. If you want a date
with millisecond support, install the GNU coreutils
package.
I encountered this on OS X, whose date
comes from BSD. The solution was to brew install coreutils
and ln -sf /usr/local/bin/gdate $HOME/bin
, and making sure that $HOME/bin
comes first in PATH
.
Use gettimeofday()
, for example:
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
struct timeval time_now;
gettimeofday(&time_now,NULL);
printf ("%ld secs, %ld usecs\n",time_now.tv_sec,time_now.tv_usec);
return 0;
}