手里的智能锁项目 , 做了个菜单,设置时间的功能 , 弄了大半天弄完了, 记录一下方法
1设置时间
设置时间需要2个结构体,分别是struct tm 和struct timeval还有一个长整型的time_t类型, 总共4个步骤。
1.1 把tm类型里的成员(年 月 日 时 分 秒)逐个赋值
struct tm {
/*
* the number of seconds after the minute, normally in the range
* 0 to 59, but can be up to 60 to allow for leap seconds
*/
int tm_sec;
/* the number of minutes after the hour, in the range 0 to 59*/
int tm_min;
/* the number of hours past midnight, in the range 0 to 23 */
int tm_hour;
/* the day of the month, in the range 1 to 31 */
int tm_mday;
/* the number of months since January, in the range 0 to 11 */
int tm_mon;
/* the number of years since 1900 */
long tm_year;
/* the number of days since Sunday, in the range 0 to 6 */
int tm_wday;
/* the number of days since January 1, in the range 0 to 365 */
int tm_yday;
};
<