美文网首页
time(NULL)获取时间戳

time(NULL)获取时间戳

作者: 编程_书恨少 | 来源:发表于2018-11-29 14:42 被阅读0次

时间: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 */
};

相关文章

网友评论

      本文标题:time(NULL)获取时间戳

      本文链接:https://www.haomeiwen.com/subject/ocqfcqtx.html