1. tm struct
Struct tm {
Int
Tm_sec;/* seconds after the minute [0-60] */
Int tm_min;
/* Minutes after the hour [0-59] */
Int tm_hour;
/* Hours since 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 Savings Time flag */
Long tm_gmtoff;
/* Offset from CUT in seconds */
Char * tm_zone;
/* Timezone abbreviation */
};
2. Use localtime to obtain the local time. The Code is as follows:
// Obtain the current time. The C library function is used. The returned value does not need to be released. The efficiency is 3-4 times higher than that of the NSDate class using OC.
-(Struct tm *) getTime
{
// Time format
Struct timeval ticks;
Gettimeofday (& ticks, nil );
Time_t now;
Struct tm * timeNow;
Time (& now );
TimeNow = localtime (& now );
TimeNow-> tm_gmtoff = ticks. TV _usec/1000; // millisecond
TimeNow-> tm_year + = 1900; // The tm_year value in tm is from 1900 to the present.
TimeNow-> tm_mon + = 1; // The tm_mon range is 0-11
Return timeNow;
}