获取系统毫秒时间的两种方法

unsigned long clockGetTimeHaoMiao2()
{
    struct timespec stv;
    clock_gettime(CLOCK_MONOTONIC, &stv);
    unsigned longt haoMiao = stv.tv_sec * 1000 + stv.tv_nsec /1000000;
    return haoMiao;
}

//FROM UTC1970-1-1 0:0:0
unsigned long clockGetRealTimeHaoMiao()
{
    struct timespec stv;
    clock_gettime(CLOCK_REALTIME, &stv);
    unsigned long haoMiao = stv.tv_sec * 1000 + stv.tv_nsec /1000000;
    return haoMiao;
}

CLOCK_MONOTONIC (系统开机开始算)  

CLOCK_REALTIME(现实真实时间,FROM UTC1970-1-1 0:0:0)

你可能感兴趣的:(c++工具类小程序)