cpp取系統時鐘

// test.cpp : 定義控制檯應用程序的入口點。
//
#pragma warning( disable : 4996 )
#include "stdafx.h"
#include "time.h"
#include "windows.h"
#include <iostream>

using namespace std;

void 取系統時間()
{
	time_t timer; //time_t實際是int64
	struct tm t; //時鐘的結構體

	time(&timer);      //取當前時間(1970年開始的秒數)
	localtime_s(&t, &timer); //把int轉爲時間結構體
	std::cout << "年:" << t.tm_year + 1900 << endl;
	cout << "月:" << t.tm_mon + 1 << endl;
	cout << "日 : " << t.tm_mday << endl;//星期是從星期日開始,星期日是0
	cout << "周:" << t.tm_wday << endl;
	cout << "一年之中:" << t.tm_yday << endl;
	cout << "時 : " << t.tm_hour << endl;
	cout << "分 : " << t.tm_min << endl;
	cout << "秒 : " << t.tm_sec << endl;
	cout << "夏令時 : " << t.tm_isdst << endl;
}

int main()
{
	取系統時間();

	getchar();
    return 0;
}

  

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