在FreeBSD中如何获得以毫秒为单位的时间? [英] How get the time in milliseconds in FreeBSD?
本文介绍了在FreeBSD中如何获得以毫秒为单位的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Linux中,我可以使用以下命令找到当前时间(以毫秒为单位):
In Linux I can find the current time in milliseconds using the command:
date +%s%N
但是在FreeBSD上我只能得到
but on FreeBSD I get only
[13:38 ]#date +%s%N
1299148740N
如何在FreeBSD中获得以毫秒(或纳秒)为单位的时间?
How can I get the time in milliseconds (or nanoseconds) in FreeBSD?
推荐答案
使用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;
}
这篇关于在FreeBSD中如何获得以毫秒为单位的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文