zoukankan      html  css  js  c++  java
  • C++获取时间函数

    https://github.com/yangzijianGit/Time

    #include <Windows.h>
    #include <time.h>
    #include <winbase.h>
    
    unsigned long long GetCurrentTimeMsec()
    {
    #ifdef _WIN32
        struct timeval tv;
        time_t clock;
        struct tm tm;
        SYSTEMTIME wtm;
        GetLocalTime(&wtm);
        tm.tm_year = wtm.wYear - 1900;
        tm.tm_mon = wtm.wMonth - 1;
        tm.tm_mday = wtm.wDay;
        tm.tm_hour = wtm.wHour;
        tm.tm_min = wtm.wMinute;
        tm.tm_sec = wtm.wSecond;
        tm.tm_isdst = -1;
        clock = mktime(&tm);
        tv.tv_sec = clock;
        tv.tv_usec = wtm.wMilliseconds * 1000;
        return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000);
    #else
        struct timeval tv;
        gettimeofday(&tv, NULL);
        return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000);
    #endif
    }
    
    unsigned long long GetCurrentTimeMsec2()
    {
        return (unsigned long long) clock();
    }
    

      clock()函数是获取当前程序启动到现在的时间, 而GetLocalTime()获取本地时间,根据需求自行选择。

  • 相关阅读:
    设计模式之中介者模式
    解释器模式(行为模式)
    进程池Pool
    Process子类
    multiprocessing
    random
    re
    time和datetime
    logging 日志
    hashlib
  • 原文地址:https://www.cnblogs.com/zijian-yang/p/14326488.html
Copyright © 2011-2022 走看看