C++ 時間戳和時間的互相轉換已經變形

#include <time.h>
void makeTime()
{
    time_t t;  //秒時間
    tm* local; //本地時間
    char buf[128] = { 0 };

    t = time(NULL); //獲取目前秒時間
    cout << t << endl;
    local = localtime(&t); //轉爲本地時間
    local->tm_hour = 0;
    local->tm_min = 0;
    local->tm_sec = 0;
    strftime(buf, 64, "%Y-%m-%d %H:%M:%S", local);
    std::cout << buf << std::endl;
    cout << mktime(local) << endl;
}


int main()
{
    makeTime();
    return 0;
}

輸出結果 :

1571800457
2019-10-23 00:00:00
1571760000
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章