c_cpp 以C为单位获取当前时间,以微秒为单位。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 以C为单位获取当前时间,以微秒为单位。相关的知识,希望对你有一定的参考价值。

#include <sys/time.h>

/**
 * Returns the current time in microseconds.
 */
long getMicrotime(){
	struct timeval currentTime;
	gettimeofday(&currentTime, NULL);
	return currentTime.tv_sec * (int)1e6 + currentTime.tv_usec;
}

以上是关于c_cpp 以C为单位获取当前时间,以微秒为单位。的主要内容,如果未能解决你的问题,请参考以下文章