C/C++>time.h

關於時間操作的標註庫


localtime() 使用 timer 的值來填充 tm 結構

在這裏插入圖片描述

#define _CRT_SECURE_NO_WARNINGS
#include <time.h>
#include <iostream>
int main()
{
	time_t ti;
	time(&ti); //獲取當前時間

	tm* time = localtime(&ti); //填充tm結構體

	std::cout << time->tm_year+1900 << std::endl; //年
	std::cout << time->tm_mon+1 << std::endl; //月
	std::cout << time->tm_mday << std::endl; //日
	std::cout << time->tm_hour << std::endl; //小時
	std::cout << time->tm_min<< std::endl; //分鐘
	std::cout << time->tm_sec << std::endl; //秒
	std::system("pause");
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章