#include //calendar time into a broken-down time expressed as UTC struct tm *gmtime(const time_t *calptr);
//converts the calendar time to the local time, taking into account the local time zone and //daylight saving time flag struct tm *localtime(const time_t *calptr);
//converts it into a time_t value time_t mktime(struct tm *tmptr);
struct tm { /* a broken-down time */ int tm_sec; /* seconds after the minute: [0 - 60] */ int tm_min; /* minutes after the hour: [0 - 59] */ int tm_hour; /* hours after midnight: [0 - 23] */ int tm_mday; /* day of the month: [1 - 31] */ int tm_mon; /* months since January: [0 - 11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday: [0 - 6] */ int tm_yday; /* days since January 1: [0 - 365] */ int tm_isdst; /* daylight saving time flag: <0, 0, >0 */ };
char *asctime(const struct tm *tmptr);
char *ctime(const time_t *calptr);
asctime()和ctime()函数产生形式的26字节字符串,这与date命令的系统默认输出形式类似: Tue Feb 10 18:27:38 2004\n\0
二、gettimeofday函数得到更精确的时间
#include <sys/time.h>
int gettimeofday(struct timeval *restrict tp, void *restrict tzp);