Add function getYears, getMonths, getDays
This commit is contained in:
parent
62fafd8eca
commit
22fff3757e
@ -148,6 +148,27 @@ int NTPClient::getMinutes() const {
|
||||
int NTPClient::getSeconds() const {
|
||||
return (this->getEpochTime() % 60);
|
||||
}
|
||||
int NTPClient::getYears() const {
|
||||
time_t rawtime = this->getEpochTime();
|
||||
struct tm* ti;
|
||||
ti = localtime(&rawtime);
|
||||
int year = ti->tm_year + 1900;
|
||||
return year;
|
||||
}
|
||||
int NTPClient::getMonths() const {
|
||||
time_t rawtime = this->getEpochTime();
|
||||
struct tm* ti;
|
||||
ti = localtime(&rawtime);
|
||||
int month = (ti->tm_mon + 1) < 10 ? 0 + (ti->tm_mon + 1) : (ti->tm_mon + 1);
|
||||
return month;
|
||||
}
|
||||
int NTPClient::getDays() const {
|
||||
time_t rawtime = this->getEpochTime();
|
||||
struct tm* ti;
|
||||
ti = localtime(&rawtime);
|
||||
int day = (ti->tm_mday) < 10 ? 0 + (ti->tm_mday) : (ti->tm_mday);
|
||||
return day;
|
||||
}
|
||||
|
||||
String NTPClient::getFormattedTime() const {
|
||||
unsigned long rawTime = this->getEpochTime();
|
||||
|
@ -85,6 +85,9 @@ class NTPClient {
|
||||
int getHours() const;
|
||||
int getMinutes() const;
|
||||
int getSeconds() const;
|
||||
int getYears() const;
|
||||
int getMonths() const;
|
||||
int getDays() const;
|
||||
|
||||
/**
|
||||
* Changes the time offset. Useful for changing timezones dynamically
|
||||
|
Loading…
Reference in New Issue
Block a user