C/C++代码获取当前时间的:年月日时分秒
2017-12-24 16:30
411 查看
直接上菜:
#include <iostream>
#include <string>
using namespace std;
static string getCurrentTimeStr()
{
time_t t = time(NULL);
char ch[64] = {0};
strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t)); //年-月-日 时-分-秒
return ch;
}
int main()
{
cout << getCurrentTimeStr() << endl;
return 0;
} 结果:
ubuntu@VM-0-13-ubuntu:~$ ./a.out
2017-12-24 16:31:17
ubuntu@VM-0-13-ubuntu:~$ date
Sun Dec 24 16:31:19 CST 2017
ubuntu@VM-0-13-ubuntu:~$
good
#include <iostream>
#include <string>
using namespace std;
static string getCurrentTimeStr()
{
time_t t = time(NULL);
char ch[64] = {0};
strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t)); //年-月-日 时-分-秒
return ch;
}
int main()
{
cout << getCurrentTimeStr() << endl;
return 0;
} 结果:
ubuntu@VM-0-13-ubuntu:~$ ./a.out
2017-12-24 16:31:17
ubuntu@VM-0-13-ubuntu:~$ date
Sun Dec 24 16:31:19 CST 2017
ubuntu@VM-0-13-ubuntu:~$
good
相关文章推荐
- 获取当前时间,年月日时分秒
- 获取系统当前时间,年月日时分秒
- JS获取当前时间年月日时分秒
- 获取当前时间年月日时分秒
- FLex 获取当前时间 年月日 时分秒
- Flex 获取当前时间和获取当前时间减去一天的时间并且格式化为年月日时分秒的形式
- js获取当前时间的年月日时分秒
- [SoapUI] 获取当前时间包括年月日时分秒来作为命名
- 获取当前时间,年月日时分秒
- C++获取当前时间中的时分秒
- Android开发中 获取当前Android的年月日时分秒的时间
- java 获取当前时间及年月日时分秒
- android获取系统当前年月日时分秒的时间
- 年月日时分秒转化为秒 和获取当前时间
- ios获取当前时间年月日时分秒
- 获取当前时间的时分秒拼接在long型的年月日后边
- Java获取当前时间的年月日时分秒方法
- javascript中获取当前时间戳和具体年月日时分秒
- ios开发 获取系统时间 取得当前的年月日,当前的时分秒获得,周几和星期几获得
- javascript获取当前时间年月日时分秒