设为首页 加入收藏

TOP

调用当前年月日
2018-11-05 16:08:48 】 浏览:80
Tags:调用 当前 年月日

直接显示当前时间:

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 }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇SPOJTLE - Time Limit Exceeded(.. 下一篇珂朵莉树(Chtholly Tree)学习笔记

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目