ESP DateTime
0.2.0
Date Time Functions and Classes for ESP8266 and ESP32
|
DateTime Library Main Class, include time get/set/format methods. More...
#include <DateTime.h>
Public Member Functions | |
DateTimeClass (const time_t _timeSecs=TIME_ZERO, const int _timeZone=DEFAULT_TIMEZONE, const char *_ntpServer=NTP_SERVER_1) | |
Construct a new DateTimeClass object. More... | |
bool | setTimeZone (int _timeZone) |
Set the TimeZone offset. More... | |
void | setServer (const char *_server) |
Set the NTP Server. More... | |
bool | forceUpdate (const unsigned int timeOutMs=DEFAULT_TIMEOUT) |
Force NTP Sync to update system timestamp for internal use, please * using begin() instead. More... | |
bool | setTime (const time_t timeSecs, bool forceSet=false) |
Set the timestamp from outside, for test only. More... | |
String | format (const char *fmt) |
Format current local time to string. More... | |
String | formatUTC (const char *fmt) |
Format current utc time to string. More... | |
bool | begin (const unsigned int timeOutMs=DEFAULT_TIMEOUT) |
Begin ntp sync to update system time. More... | |
bool | isTimeValid () const |
Check current timestamp is or not valid time. More... | |
time_t | getBootTime () const |
Get system boot timestamp in seconds. More... | |
time_t | now () const |
Get current local timestamp, alias of getTime() More... | |
time_t | getTime () const |
Get current local timestamp. More... | |
time_t | utcTime () const |
Get current utc timestamp. More... | |
time_t | osTime () const |
Get system timestamp using time(nullptr), please use now() instead. More... | |
int | getTimeZone () const |
Get current timezone offset. More... | |
const char * | getServer () |
Get current ntp server address. More... | |
DateTimeParts | getParts () |
Get DateTimeParts object. More... | |
String | toString () |
String simple string representation of local time. More... | |
String | toISOString () |
String ISO8601 representation of local time. More... | |
String | toUTCString () |
String RFC1123 representation of local time. More... | |
DateTimeClass | operator+ (const time_t timeDeltaSecs) |
DateTimeClass | operator- (const time_t timeDeltaSecs) |
DateTimeClass & | operator-= (const time_t timeDeltaSecs) |
DateTimeClass & | operator+= (const time_t timeDeltaSecs) |
Static Public Attributes | |
constexpr static time_t | SECS_START_POINT = 1574870400 |
Valid min timestamp value 1574870400 (2019/11/28 00:00:00). More... | |
constexpr static time_t | TIME_ZERO = 0 |
Unix Time Zero constant (1970-01-01 00:00:00) More... | |
constexpr static int | TIMEZONE_UTC = 0 |
UTC TimeZone Offset GMT+0. More... | |
constexpr static int | TIMEZONE_CHINA = 8 |
TimeZone Offset GMT+8. More... | |
constexpr static int | DEFAULT_TIMEZONE = TIMEZONE_UTC |
Default TimeZone Offset GMT+0. More... | |
constexpr static unsigned int | DEFAULT_TIMEOUT = 10 * 1000 |
NTP Request default timeout: 10 seconds. More... | |
constexpr static const char * | NTP_SERVER_1 = "ntp.ntsc.ac.cn" |
NTP Server 1. More... | |
constexpr static const char * | NTP_SERVER_2 = "pool.ntp.org" |
NTP Server 2. More... | |
constexpr static const char * | NTP_SERVER_3 = "time.windows.com" |
NTP Server 3. More... | |
Friends | |
bool | operator< (const DateTimeClass &lhs, const DateTimeClass &rhs) |
bool | operator> (const DateTimeClass &lhs, const DateTimeClass &rhs) |
bool | operator<= (const DateTimeClass &lhs, const DateTimeClass &rhs) |
bool | operator>= (const DateTimeClass &lhs, const DateTimeClass &rhs) |
bool | operator== (const DateTimeClass &lhs, const DateTimeClass &rhs) |
bool | operator!= (const DateTimeClass &lhs, const DateTimeClass &rhs) |
DateTime Library Main Class, include time get/set/format methods.
DateTimeClass::DateTimeClass | ( | const time_t | _timeSecs = TIME_ZERO , |
const int | _timeZone = DEFAULT_TIMEZONE , |
||
const char * | _ntpServer = NTP_SERVER_1 |
||
) |
Construct a new DateTimeClass object.
_timeSecs | set initialize timestamp |
_timeZone | set initialize timezone offset |
_ntpServer | set initialize ntp server |
|
inline |
Begin ntp sync to update system time.
timeOutMs | ntp request timeout |
bool DateTimeClass::forceUpdate | ( | const unsigned int | timeOutMs = DEFAULT_TIMEOUT | ) |
Force NTP Sync to update system timestamp for internal use, please * using begin() instead.
timeOutMs | ntp request timeout |
String DateTimeClass::format | ( | const char * | fmt | ) |
Format current local time to string.
Attention: ESP8266 does not support real timezone, it just add timeZone 3600 seconds to original timestamp, so z format is always +0000
fmt | date time format |
String DateTimeClass::formatUTC | ( | const char * | fmt | ) |
Format current utc time to string.
fmt | date time format |
|
inline |
Get system boot timestamp in seconds.
|
inline |
Get DateTimeParts object.
|
inline |
Get current ntp server address.
|
inline |
Get current local timestamp.
|
inline |
Get current timezone offset.
|
inline |
Check current timestamp is or not valid time.
|
inline |
Get current local timestamp, alias of getTime()
|
inline |
Get system timestamp using time(nullptr), please use now() instead.
void DateTimeClass::setServer | ( | const char * | _server | ) |
Set the NTP Server.
_server | ntp server domain name or ip address |
bool DateTimeClass::setTime | ( | const time_t | timeSecs, |
bool | forceSet = false |
||
) |
Set the timestamp from outside, for test only.
timeSecs | timestamp in seconds |
forceSet | ignore valid check, force set |
bool DateTimeClass::setTimeZone | ( | int | _timeZone | ) |
Set the TimeZone offset.
_timeZone | time zone offset value |
|
inline |
String ISO8601 representation of local time.
|
inline |
String simple string representation of local time.
|
inline |
String RFC1123 representation of local time.
|
inline |
Get current utc timestamp.
|
staticconstexpr |
NTP Request default timeout: 10 seconds.
|
staticconstexpr |
Default TimeZone Offset GMT+0.
|
staticconstexpr |
NTP Server 1.
|
staticconstexpr |
NTP Server 2.
|
staticconstexpr |
NTP Server 3.
|
staticconstexpr |
Valid min timestamp value 1574870400 (2019/11/28 00:00:00).
return value from time(null) < 1574870400 means system time invalid
|
staticconstexpr |
Unix Time Zero constant (1970-01-01 00:00:00)
|
staticconstexpr |
TimeZone Offset GMT+8.
|
staticconstexpr |
UTC TimeZone Offset GMT+0.