获取系统本地的日期和时间

#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;

int main()
{
	struct tm t;			// tm结构指针
	time_t now;			// 声明time_t类型变量
	time(&now);			// 获取系统日期和时间
	localtime_s(&t, &now);	     // 获取本地日期和时间

	cout << "年:\t\t" << t.tm_year + 1900 << endl;
	cout << "月:\t\t" << t.tm_mon + 1 << endl;
	cout << "日:\t\t" << t.tm_mday << endl;
	cout << "星期:\t\t" << t.tm_wday << endl;
	cout << "当年的第:\t" << t.tm_yday << "\t天" << endl;
	cout << "时:\t\t" << t.tm_hour << endl;
	cout << "分:\t\t" << t.tm_min << endl;
	cout << "秒:\t\t" << t.tm_sec << endl;
	cout << "夏令时:\t" << t.tm_isdst << endl;

	system("pause");
	return 0;
}

 运行:

 

posted @ 2017-11-03 23:47  半生戎马,共话桑麻、  阅读(231)  评论(0)    收藏  举报
levels of contents