struct tm,time,localtime,mktime,ctime,gmtime,difftime,asctime,strftime

原文链接 

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;
}

猜你喜欢

转载自blog.csdn.net/qq_31918961/article/details/106469262