Java中以毫秒级别返回系统时间的函数是:System.currentTimeMillis(),返回类型时64位的长整形数字。
而C++中有很多选择可以用来表示时间,这里选用了 gettimeofday() -- 获取当前时间(保存在结构体timeval中)
具体实现如下:
#include <sys/time.h>
#include <time.h>
typedef long long int64;
class LogTimeMM
{
public:
static int64 getSystemTime(){
struct timeval tv; //获取一个时间结构
gettimeofday(&tv, NULL); //获取当前时间
int64 t = tv.tv_sec;
t *=1000;
t +=tv.tv_usec/1000;
return t;
}
};
具体使用过程:
printf("%lld",LogTimeMM::getSystemTime());