在Linux中,我可以使用以下命令找到以毫秒为单位的当前时间:
date +%s%N但在FreeBSD上我只能
[13:38 ]#date +%s%N
1299148740N如何获取以毫秒(或纳秒)为单位的FreeBSD时间?
发布于 2011-03-04 03:40:01
使用gettimeofday(),例如:
#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;
}发布于 2013-02-03 00:44:32
BSD date命令不支持毫秒。如果您想要一个支持毫秒的date,请安装GNU coreutils包。
我在OS上遇到了这个问题,它的date来自于BSD。解决方案是brew install coreutils和ln -sf /usr/local/bin/gdate $HOME/bin,并确保$HOME/bin在PATH中排在第一位。
发布于 2011-03-03 23:48:18
尝试从daemontools使用tai64n
$ echo | tai64n | tai64nlocal
2011-03-03 09:45:37.833010500
$ ps | tai64n | tai64nlocal
2011-03-03 09:52:30.817146500 PID TTY TIME CMD
2011-03-03 09:52:30.817150500 7154 pts/1 00:00:07 bash
2011-03-03 09:52:30.817157500 20099 pts/1 00:00:00 ps
2011-03-03 09:52:30.817159500 20100 pts/1 00:00:00 tai64n
2011-03-03 09:52:30.817162500 20101 pts/1 00:00:00 tai64nlocalhttps://stackoverflow.com/questions/5179559
复制相似问题