/*
* Returns time in s.usec
*/
float mtime()
{
struct timeval stime;
gettimeofday(&stime,0x0);
return (float)stime.tv_sec+((float)stime.tv_usec)/1000000000;
}
main(){
while(true){
cout<<setprecision(15)<<mtime()<<endl;
// shows the same time irregularly for some reason and can mess up triggers
usleep(500000);
}
}
为什么它不规则地显示相同的时间?(在 ubuntu 64 位和 C++ 上编译)还有哪些其他标准方法可用于生成毫秒精度的 unix 时间戳?