调用当前年月日

直接显示当前时间:

1 #include <iostream>
2 #include <ctime>
3 using namespace std;
4 int main()
5 {
6     time_t now = time(0);
7     char *dt = ctime(&now);
8     cout << dt;
9 }

显示当前的年月日,时分秒:

 1 #include <iostream>
 2 #include <ctime>
 3 using namespace std;
 4 int main()
 5 {
 6     time_t now = time(0);
 7     tm *ltm = localtime(&now);
 8     cout << "" << 1900 + ltm->tm_year << endl;
 9     cout << "" << 1 + ltm->tm_mon << endl;
10     cout << "" << ltm->tm_mday << endl;
11     cout << "" << ltm->tm_hour << endl;
12     cout << "" << ltm->tm_min << endl;
13     cout << "" << ltm->tm_sec << endl;
14 }

 

posted @ 2018-11-05 14:10  会武术之白猫  阅读(268)  评论(0编辑  收藏  举报