diff --git a/NTPClient.cpp b/NTPClient.cpp index b435855..13780de 100755 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -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(); diff --git a/NTPClient.h b/NTPClient.h index a31d32f..cc26b78 100755 --- a/NTPClient.h +++ b/NTPClient.h @@ -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