C语言time(null)在oc中的用法
time_t time1 = time(NULL);//获取系统时间,单位为秒;
struct tm * time = localtime(&time1);//转换成tm类型的结构体;
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
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 */
};
重点是看后面的英文,文档描述的,首先使用time(null)获取当前日期的秒数,换成当前时间后,打印time可以看到当前日期的其他属性,比如当前的年数,是从1900年开始的,所以要加1900,月份是用0-11,其他诸如。所以计算当前日期是周几,距某日有多少天,多少周等等这些问题用这个就可以算出来了。记下来,备注用
其他文章请移步个人博客:http://zhangqq166.cn/