c++ 获取当前时间

来源:互联网 发布:个体营业执照 网络经营 编辑:程序博客网 时间:2024/04/30 09:48

#include <iostream>

#include <time.h>

using namespace std;

int main()

{

time_t ltime;
char tmpbuf[128];

//方法1:分别获取当前时间,日期
/* Display operating system-style date and time. */
     _strtime( tmpbuf );
     printf( "OS time://t//t//t//t%s//n", tmpbuf ); //打印当前时间
     _strdate( tmpbuf );
     printf( "OS date://t//t//t//t%s//n", tmpbuf ); //打印当前日期

//方法二:获取当前时间日期
time(&ltime); //获取从1970至今经过的秒数

cout << ctime(&ltime) << endl; //折算成当前时间日期

return 0;

}

原创粉丝点击