时间:2018-11-29
- (void)viewDidLoad {
[super viewDidLoad];
time_t time1 = time(NULL);//获取系统时间,单位为秒;
struct tm * time = localtime(&time1);//转换成tm类型的结构体;
NSLog(@"----%d", time->tm_year + 1900); // 获取当前的年份
}
系统定义的tm
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 UTC in seconds */
char *tm_zone; /* timezone abbreviation */
};
网友评论