原文链接
1. struct tm
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;
2. time
Get current time
time_t time ( time_t * timer );
Example
/ *time example* /
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t seconds;
time(&seconds);
//或者seconds = time(NULL);
cout << seconds / 3600 << " hours since January 1,1970" << endl;
return 0;
}
3. localtime
<ctime>
struct tm * localtime ( const time_t * timer );
Convert time_t to tm as local time
Example
/*localtime example*/
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t rawtime;
struct tm* timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
cout << "current local time and date: " << asctime(timeinfo);
return 0;
}