#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