Simple general-purpose date/time class (no TZ / DST / leap seconds). More...
Public Types
enum
| |
timestampOpt { | TIMESTAMP_FULL , |
TIMESTAMP_TIME , | TIMESTAMP_DATE } |
Protected Attributes
| |
yOff Year offset from 2000. | |
m Month 1-12. | |
d Day 1-31. | |
hh Hours 0-23. | |
mm Minutes 0-59. | |
ss Seconds 0-59. |
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.
Format of the ISO 8601 timestamp generated by
timestamp()
. Each option corresponds to a
toString()
format as follows:
Enumerator | |
---|---|
TIMESTAMP_FULL |
|
TIMESTAMP_TIME |
|
TIMESTAMP_DATE |
|
Constructor from Unix time .
This builds a DateTime from an integer specifying the number of seconds elapsed since the epoch: 1970-01-01 00:00:00. This number is analogous to Unix time, with two small differences:
If called without argument, it returns the earliest time representable by this class: 2000-01-01 00:00:00.
unixtime()
method is the converse of this constructor.
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).
isValid()
method can be used to test whether the constructed
DateTime
is valid.
Copy constructor.
const char * time |
Constructor for generating the build time.
This constructor expects its parameters to be strings in the format generated by the compiler's preprocessor macros
__DATE__
and
__TIME__
. Usage:
F()
macro can be used to reduce the RAM footprint, see the next constructor.
const __FlashStringHelper * time |
Memory friendly constructor for generating the build time.
This version is intended to save RAM by keeping the date and time strings in program memory. Use it with the
F()
macro:
Constructor for creating a DateTime from an ISO8601 date string.
This constructor expects its parameters to be a string in the https://en.wikipedia.org/wiki/ISO_8601 format, e.g:
"2020-06-25T15:29:37"
Usage:
DateTime dt( "2020-06-25T15:29:37"); The year must be > 2000, as only the yOff is considered. Parameters/*F******************************************************************** * **********************************************************************/ bool DateTime::isValid()constCheck whether this DateTime is valid.
Returnstrue if valid, false if not.
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 |
---|---|
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.
timestamp()
method provides similar functionnality, but it returns a
String
object and supports a limited choice of predefined formats.
[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.
|
Serial.println(now.toString(buffer));
| inline |
Return the year.
| inline |
Return the month.
| inline |
Return the day of the month.
| inline |
Return the hour.
Return the hour in 12-hour format.
| inline |
Return whether the time is PM.
| inline |
Return the minute.
| inline |
Return the second.
Return the day of the week.
Convert the DateTime to seconds since 1 Jan 2000.
The result can be converted back to a DateTime with:
Return Unix time: seconds since 1 Jan 1970.
DateTime::DateTime(uint32_t)
constructor is the converse of this method.
Return a ISO 8601 timestamp as a
String
object.
The generated timestamp conforms to one of the predefined, ISO 8601-compatible formats for representing the date (if
opt
is
TIMESTAMP_DATE
), the time (
TIMESTAMP_TIME
), or both (
TIMESTAMP_FULL
).
toString()
method provides more general string formatting.
Add a TimeSpan to the DateTime object.
Subtract a TimeSpan from the DateTime object.
Subtract one DateTime from another.
Test if one DateTime is less (earlier) than another.
isValid()
method to check if
DateTime
object is valid
| inline |
Test if one DateTime is greater (later) than another.
isValid()
method to check if
DateTime
object is valid
| inline |
Test if one DateTime is less (earlier) than or equal to another.
isValid()
method to check if
DateTime
object is valid
| inline |
Test if one DateTime is greater (later) than or equal to another.
isValid()
method to check if
DateTime
object is valid
Test if two DateTime objects are equal.
isValid()
method to check if
DateTime
object is valid
| inline |
Test if two DateTime objects are not equal.
isValid()
method to check if
DateTime
object is valid