C++获得系统时间


#include <iostream> #include "time.h" //#include "stdlib.h" using namespace std; int main() { time_t rawtime; //时间变量 struct tm * timeinfo; //时间的结构指针 time ( &rawtime ); //-- 获取时间,以秒计,从1970年1月一日起算,存于rawtime timeinfo = localtime ( &rawtime ); //ocaltime ( &rawtime ); -- 转为当地时间,//返回时间结构指针 cout<<"账户创建时间:"<<asctime (timeinfo)<<endl; //asctime ()-- 转为标准ASCII时间格式: 星期 月 日 时:分:秒 年 //还可以单独获取各种时间元素 cout<<(timeinfo->tm_sec);//获得秒 cout<<timeinfo->tm_min;//获得分 return 0; } /* time_t -- 时间类型(time.h 定义) struct tm -- 时间结构,time.h 定义如下: int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; */

  

原文地址:https://www.cnblogs.com/dakou/p/2982532.html