C++中系统时间的提取
struct Time
{
int year;
int month;
int date;
int hour;
int minute;
int second;
void getnow();
};
void Time::getnow()
{
struct tm *times; //定义时间指针变量.....(只能用指针)
time_t t; //定义系统时间变量,供提供系统时间
t = time(0); //当前系统时间给变量t
times = localtime(&t); //把系统时间变量强制转换成tm结构体形式时间
year=(times->tm_year+1900);
month=times->tm_mon;
date=times->tm_mday;
hour=times->tm_hour;
minute=times->tm_min;
second=times->tm_sec;
}
需加上time.h