arduino中time.h的使用方法

阅读: 评论:0

arduino中time.h的使用方法

arduino中time.h的使用方法

官方文档地址:/

  1. 变量类型

首先,在TimeLib.h中,定义了
typedef unsigned long time_t;
time_t 的取值范围0~4294967295,表示的是1970年1月1日以来的秒数。

  1. 主要函数
int     hour();            // the hour now 
int     hour(time_t t);    // the hour for the given time
int     hourFormat12();    // the hour now in 12 hour format
int     hourFormat12(time_t t); // the hour for the given time in 12 hour format
uint8_t isAM();            // returns true if time now is AM
uint8_t isAM(time_t t);    // returns true the given time is AM
uint8_t isPM();            // returns true if time now is PM
uint8_t isPM(time_t t);    // returns true the given time is PM
int     minute();          // the minute now 
int     minute(time_t t);  // the minute for the given time
int     second();          // the second now 
int     second(time_t t);  // the second for the given time
int     day();             // the day now 
int     day(time_t t);     // the day for the given time
int     weekday();         // the weekday now (Sunday is day 1) 
int     weekday(time_t t); // the weekday for the given time 
int     month();           // the month now  (Jan is month 1)
int     month(time_t t);   // the month for the given time
int     year();            // the full four digit year: (2009, 2010 etc) 
int     year(time_t t);    // the year for the given time
  1. 设置系统时间

设置系统时间的方法有两种,一种用秒数,另一种是使用年月日等多个参数。

void setTime(time_t t) { 
#ifdef TIME_DRIFT_INFOif(sysUnsyncedTime == 0) sysUnsyncedTime = t;   // store the time of the first call to set a valid Time   
#endifsysTime = (uint32_t)t;  nextSyncTime = (uint32_t)t + syncInterval;Status = timeSet;prevMillis = millis();  // restart counting from now (thanks to Korman for this fix)
} void setTime(int hr,int min,int sec,int dy, int mnth, int yr){// year can be given as full four digit year or two digts (2010 or 10 for 2010);  //it is converted to years since 1970if( yr > 99)yr = yr - 1970;elseyr += 30;  tm.Year = yr;tm.Month = mnth;tm.Day = dy;tm.Hour = hr;tm.Minute = min;tm.Second = sec;setTime(makeTime(tm));
}

在与ds1307的通讯中,又使用了下面的方法

 );   // the function to get the time from the RTC
void setSyncProvider( getExternalTime getTimeFunction){getTimePtr = getTimeFunction;  nextSyncTime = sysTime;now(); // this will sync the clock
}

本文发布于:2024-01-30 14:19:27,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170659556820611.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:使用方法   arduino   time
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23