Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DateTime Class Reference
Simple general-purpose date/time class (no TZ / DST / leap second handling!). See http://en.wikipedia.org/wiki/Leap_second. More...
#include <RTClib.h>
Public Types | |
| enum | timestampOpt |
ISO 8601 Timestamp function. More... | |
Public Member Functions | |
| DateTime (uint32_t t=SECONDS_FROM_1970_TO_2000) | |
| DateTime constructor from unixtime. | |
| DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour=0, uint8_t min=0, uint8_t sec=0) | |
| DateTime constructor from Y-M-D H:M:S. | |
| DateTime (const DateTime ©) | |
| DateTime copy constructor using a member initializer list. | |
| DateTime (const char *date, const char *time) | |
| A convenient constructor for using "the compiler's time": DateTime now (__DATE__, __TIME__); NOTE: using F() would further reduce the RAM footprint, see below. | |
| char * | tostring (char *buffer) |
| A convenient constructor for using "the compiler's time": This version will save RAM by using PROGMEM to store it by using the F macro. DateTime now (F(__DATE__), F(__TIME__));. | |
| uint16_t | year () const |
| Return the year, stored as an offset from 2000. | |
| uint8_t | month () const |
| Return month. | |
| uint8_t | day () const |
| Return day. | |
| uint8_t | hour () const |
| Return hours. | |
| uint8_t | minute () const |
| Return minutes. | |
| uint8_t | second () const |
| Return seconds. | |
| uint8_t | dayOfTheWeek () const |
| Return the day of the week for this object, from 0-6. | |
| long | secondstime () const |
| 32-bit times as seconds since 1/1/2000 | |
| uint32_t | unixtime (void) const |
| 32-bit times as seconds since 1/1/1970 | |
| string | timestamp (timestampOpt opt=TIMESTAMP_FULL) |
| ISO 8601 Timestamp. | |
| DateTime | operator+ (const TimeSpan &span) |
| Add a TimeSpan to the DateTime object. | |
| DateTime | operator- (const TimeSpan &span) |
| Subtract a TimeSpan from the DateTime object. | |
| TimeSpan | operator- (const DateTime &right) |
| Subtract one DateTime from another. | |
| bool | operator< (const DateTime &right) const |
| Is one DateTime object less than (older) than the other? | |
| bool | operator> (const DateTime &right) const |
| Test if one DateTime is greater (later) than another. | |
| bool | operator<= (const DateTime &right) const |
| Test if one DateTime is less (earlier) than or equal to another. | |
| bool | operator>= (const DateTime &right) const |
| Test if one DateTime is greater (later) than or equal to another. | |
| bool | operator== (const DateTime &right) const |
| Is one DateTime object equal to the other? | |
| bool | operator!= (const DateTime &right) const |
| Test if two DateTime objects not equal. | |
Protected Attributes | |
| uint8_t | yOff |
| Year offset from 2000. | |
| uint8_t | m |
| Month 1-12. | |
| uint8_t | d |
| Day 1-31. | |
| uint8_t | hh |
| Hours 0-23. | |
| uint8_t | mm |
| Minutes 0-59. | |
| uint8_t | ss |
| Seconds 0-59. | |
Detailed Description
Simple general-purpose date/time class (no TZ / DST / leap second handling!). See http://en.wikipedia.org/wiki/Leap_second.
Definition at line 62 of file RTClib.h.
Member Enumeration Documentation
| enum timestampOpt |
Constructor & Destructor Documentation
| DateTime | ( | uint32_t | t = SECONDS_FROM_1970_TO_2000 ) |
DateTime constructor from unixtime.
- Parameters:
-
t Initial time in seconds since Jan 1, 1970 (Unix time)
Definition at line 141 of file RTClib.cpp.
| DateTime | ( | uint16_t | year, |
| uint8_t | month, | ||
| uint8_t | day, | ||
| uint8_t | hour = 0, |
||
| uint8_t | min = 0, |
||
| uint8_t | sec = 0 |
||
| ) |
DateTime constructor from Y-M-D H:M:S.
- Parameters:
-
year Year, 2 or 4 digits (year 2000 or higher) month Month 1-12 day Day 1-31 hour 0-23 min 0-59 sec 0-59
Definition at line 180 of file RTClib.cpp.
DateTime copy constructor using a member initializer list.
- Parameters:
-
copy DateTime object to copy
Definition at line 198 of file RTClib.cpp.
| DateTime | ( | const char * | date, |
| const char * | time | ||
| ) |
A convenient constructor for using "the compiler's time": DateTime now (__DATE__, __TIME__); NOTE: using F() would further reduce the RAM footprint, see below.
- Parameters:
-
date Date string, e.g. "Dec 26 2009" time Time string, e.g. "12:34:56"
Definition at line 230 of file RTClib.cpp.
Member Function Documentation
| uint8_t dayOfTheWeek | ( | ) | const |
Return the day of the week for this object, from 0-6.
- Returns:
- Day of week 0-6 starting with Sunday, e.g. Sunday = 0, Saturday = 6
Definition at line 366 of file RTClib.cpp.
| uint8_t minute | ( | ) | const |
| bool operator!= | ( | const DateTime & | right ) | const |
Subtract one DateTime from another.
- Parameters:
-
right The DateTime object to subtract from self (the left object)
- Returns:
- TimeSpan of the difference between DateTimes
Definition at line 433 of file RTClib.cpp.
| bool operator< | ( | const DateTime & | right ) | const |
Is one DateTime object less than (older) than the other?
- Parameters:
-
right Comparison DateTime object
- Returns:
- True if the left object is older than the right object
Definition at line 445 of file RTClib.cpp.
| bool operator<= | ( | const DateTime & | right ) | const |
| bool operator== | ( | const DateTime & | right ) | const |
Is one DateTime object equal to the other?
- Parameters:
-
right Comparison DateTime object
- Returns:
- True if both DateTime objects are the same
Definition at line 457 of file RTClib.cpp.
| bool operator> | ( | const DateTime & | right ) | const |
| bool operator>= | ( | const DateTime & | right ) | const |
| uint8_t second | ( | ) | const |
| long secondstime | ( | void | ) | const |
32-bit times as seconds since 1/1/2000
Convert the DateTime to seconds.
- Returns:
- The object as seconds since 2000-01-01
Definition at line 394 of file RTClib.cpp.
| string timestamp | ( | timestampOpt | opt = TIMESTAMP_FULL ) |
ISO 8601 Timestamp.
- Parameters:
-
opt Format of the timestamp
- Returns:
- Timestamp string, e.g. "2000-01-01T12:34:56"
Definition at line 469 of file RTClib.cpp.
| char * tostring | ( | char * | buffer ) |
A convenient constructor for using "the compiler's time": This version will save RAM by using PROGMEM to store it by using the F macro. DateTime now (F(__DATE__), F(__TIME__));.
- Parameters:
-
date Date string, e.g. "Dec 26 2009" time Time string, e.g. "12:34:56"
Return DateTime in based on user defined format.
- Parameters:
-
buffer,: array of char for holding the format description and the formatted DateTime. Before calling this method, the buffer should be initialized by the user with a format string, e.g. "YYYY-MM-DD hh:mm:ss". The method will overwrite the buffer with the formatted date and/or time.
- Returns:
- a pointer to the provided buffer. This is returned for convenience, in order to enable idioms such as Serial.println(now.tostring(buffer));
Definition at line 311 of file RTClib.cpp.
| uint32_t unixtime | ( | void | ) | const |
32-bit times as seconds since 1/1/1970
Return unix time, seconds since Jan 1, 1970.
- Returns:
- Number of seconds since Jan 1, 1970
Definition at line 378 of file RTClib.cpp.
| uint16_t year | ( | ) | const |
Field Documentation
Generated on Wed Jul 13 2022 06:14:12 by
1.7.2