-
-
Notifications
You must be signed in to change notification settings - Fork 128
RtcDateTime object
RtcDateTime represents the time and date in one object.
Its primary purpose is to retrieve and set the time on the Rtc objects. It is not a general-purpose time object and lacks support for time-zones and daylight savings time adjustments.
Construct the RtcDateTime from seconds.
secondsFrom2000 - the number of seconds since Jan 1, 2000. This is not UNIX nor NTP date time.
RtcDateTime(uint16_t year, uint8_t month, uint8_t dayOfMonth, uint8_t hour, uint8_t minute, uint8_t second)
Construct the RtcDateTime from individual values of the date and time.
Construct the RtcDateTime from the compilation format of date and time of "Dec 06 2023" and "14:34:56".
RtcDateTime compileDateTime(__DATE__, __TIME__);
Basic validity test of values. It does not check time zones or daylight savings time.
<return>, true if values represent a valid date and time
<return>, the four digit year, like 2023.
<return>, the month
<return>, the day
<return>, the hour, in 24 hours format
<return>, the minutes
<return>, the seconds
<return>, the day of the week, where the day of the week starts on Sunday with a value of 0. You can assign it to an enum DayOfWeek.
Initialize the RtcDateTime from a NTP time uint32_t.
secondsSince1900 - a time value in 32 bit NTP time space.
Initialize the RtcDateTime from a NTP time uint64_t.
secondsSince1900 - a time value in 64 bit NTP time space.
Initialize the RtcDateTime from a Unix time uint32_t.
secondsSince1970 - a time value in 32 bit Unix time space.
Initialize the RtcDateTime from a Unix time uint64_t.
secondsSince1970 - a time value in 64 bit Unix time space.
template <typename T_LOCALE> size_t InitWithDateTimeFormatString(const char* format, const char* datetime)
Initialize the RtcDateTime from a string using the given time format string using the given localization model.
T_LOCALE - (defaults to RtcLocaleEnUs) Localization model object, currently only RtcLocaleEnUs or RtcLocaleEn.
format - a string format used to parse the given date time string. This string is expected to be PROGMEM, so wrap with F(). See InitWithDateTimeFormatString Format Details for more information on how to assemble one.
datetime - a string that is parsed using the given format.
A simple example supporting a limited number of time-zone abbreviations:
rtcNow.InitWithDateTimeFormatString(F("*, DD MMM YYYY hh:mm:ss zzz"), dateString);
A example using the template argument to use a more comprehensive time-zone abbreviations:
rtcNow.InitWithDateTimeFormatString<RtcLocaleEn>(F("*, DD MMM YYYY hh:mm:ss zzz"), dateString);
This allows for comparing if two RtcDateTime are the same.
if (time == now) {
}
This allows for comparing if two RtcDateTime are not the same.
if (time != matchTime) {
}
This allows for comparing if a RtcDateTime is less than or equal to another RtcDateTime.
if (now <= alarm) {
}
This allows for comparing if a RtcDateTime is greater than or equal to another RtcDateTime.
if (alarm >= now) {
}
This allows for comparing if a RtcDateTime is less than another RtcDateTime.
if (now < alarm) {
}
This allows for comparing if a RtcDateTime is greater than another RtcDateTime.
if (alarm > now) {
}
This allows for seconds to be added to the time.
time += 60; // add a minute
This allows for seconds to be added with a RtcDateTime.
stdTime = time + 60 * 60; // add an hour with time
This allows for seconds to be subtracted from the time.
time -= 60; // remove a minute
This allows for seconds to be subtracted with a RtcDateTime.
dstTime = time - 60 * 60; // remove an hour with time
This allows for signed seconds to be added to the time.
time += -60; // add a minus 60 seconds, thus remove
This allows for signed seconds to be added with a RtcDateTime.
int32_t offset = -360; // minus an hour
localTime = time + offset;
<return>, the total seconds since 1/1/2000. This is not UNIX nor NTP time.
<return>, the total seconds since 1/1/2000. This is not UNIX nor NTP time.
<return>, the total days since 1/1/2000.
Calculate the next day from this object that falls on the given day of week provided.
<dayOfWeek>, the day of the week, starts on Sunday with a value of 0. You can use enum DayOfWeek.
<return>, the RtcDateTime calculated. If this objects day of the week is the same as the given day of the week, it will return a copy of this object.
<return>, a Unix time value.
<return>, a Unix time value.
<return>, a NTP time value.
<return>, a NTP time value.
<return>, the number of days in the month of the given year. It does account for leap years.
<return>, true if the given year is a leap year.