|
| DateTime (uint32_t t=SECONDS_FROM_1970_TO_2000) |
| Constructor from Unix time. More...
|
|
| DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour=0, uint8_t min=0, uint8_t sec=0) |
| Constructor from (year, month, day, hour, minute, second). More...
|
|
| DateTime (const DateTime ©) |
| Copy constructor. More...
|
|
| DateTime (const char *date, const char *time) |
| Constructor for generating the build time. More...
|
|
| DateTime (const __FlashStringHelper *date, const __FlashStringHelper *time) |
| Memory friendly constructor for generating the build time. More...
|
|
| DateTime (const char *iso8601date) |
| Constructor for creating a DateTime from an ISO8601 date string. More...
|
|
bool | isValid () const |
| Check whether this DateTime is valid. More...
|
|
char * | toString (char *buffer) const |
| Writes the DateTime as a string in a user-defined format. More...
|
|
uint16_t | year () const |
| Return the year. More...
|
|
uint8_t | month () const |
| Return the month. More...
|
|
uint8_t | day () const |
| Return the day of the month. More...
|
|
uint8_t | hour () const |
| Return the hour. More...
|
|
uint8_t | twelveHour () const |
| Return the hour in 12-hour format. More...
|
|
uint8_t | isPM () const |
| Return whether the time is PM. More...
|
|
uint8_t | minute () const |
| Return the minute. More...
|
|
uint8_t | second () const |
| Return the second. More...
|
|
uint8_t | dayOfTheWeek () const |
| Return the day of the week. More...
|
|
uint32_t | secondstime () const |
| Convert the DateTime to seconds since 1 Jan 2000. More...
|
|
uint32_t | unixtime (void) const |
| Return Unix time: seconds since 1 Jan 1970. More...
|
|
String | timestamp (timestampOpt opt=TIMESTAMP_FULL) const |
| Return a ISO 8601 timestamp as a String object. More...
|
|
DateTime | operator+ (const TimeSpan &span) const |
| Add a TimeSpan to the DateTime object. More...
|
|
DateTime | operator- (const TimeSpan &span) const |
| Subtract a TimeSpan from the DateTime object. More...
|
|
TimeSpan | operator- (const DateTime &right) const |
| Subtract one DateTime from another. More...
|
|
bool | operator< (const DateTime &right) const |
| Test if one DateTime is less (earlier) than another. More...
|
|
bool | operator> (const DateTime &right) const |
| Test if one DateTime is greater (later) than another. More...
|
|
bool | operator<= (const DateTime &right) const |
| Test if one DateTime is less (earlier) than or equal to another. More...
|
|
bool | operator>= (const DateTime &right) const |
| Test if one DateTime is greater (later) than or equal to another. More...
|
|
bool | operator== (const DateTime &right) const |
| Test if two DateTime objects are equal. More...
|
|
bool | operator!= (const DateTime &right) const |
| Test if two DateTime objects are not equal. More...
|
|
Simple general-purpose date/time class (no TZ / DST / leap seconds).
This class stores date and time information in a broken-down form, as a tuple (year, month, day, hour, minute, second). The day of the week is not stored, but computed on request. The class has no notion of time zones, daylight saving time, or leap seconds: time is stored in whatever time zone the user chooses to use.
The class supports dates in the range from 1 Jan 2000 to 31 Dec 2099 inclusive.
char * DateTime::toString |
( |
char * |
buffer | ) |
const |
Writes the DateTime as a string in a user-defined format.
The buffer parameter should be initialized by the caller with a string specifying the requested format. This format string may contain any of the following specifiers:
specifier | output |
YYYY | the year as a 4-digit number (2000–2099) |
YY | the year as a 2-digit number (00–99) |
MM | the month as a 2-digit number (01–12) |
MMM | the abbreviated English month name ("Jan"–"Dec") |
DD | the day as a 2-digit number (01–31) |
DDD | the abbreviated English day of the week ("Mon"–"Sun") |
AP | either "AM" or "PM" |
ap | either "am" or "pm" |
hh | the hour as a 2-digit number (00–23 or 01–12) |
mm | the minute as a 2-digit number (00–59) |
ss | the second as a 2-digit number (00–59) |
If either "AP" or "ap" is used, the "hh" specifier uses 12-hour mode (range: 01–12). Otherwise it works in 24-hour mode (range: 00–23).
The specifiers within buffer will be overwritten with the appropriate values from the DateTime. Any characters not belonging to one of the above specifiers are left as-is.
Example: The format "DDD, DD MMM YYYY hh:mm:ss" generates an output of the form "Thu, 16 Apr 2020 18:34:56.
- See also
- The
timestamp()
method provides similar functionnality, but it returns a String
object and supports a limited choice of predefined formats.
- Parameters
-
[in,out] | 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 the format string. 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));