Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to get day of month #120

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Added function to get dayof month - 2020.10.07

NTPClient 3.1.0 - 2016.05.31

* Added functions for changing the timeOffset and updateInterval later. Thanks @SirUli
Expand Down
10 changes: 9 additions & 1 deletion NTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ unsigned long NTPClient::getEpochTime() const {
int NTPClient::getDay() const {
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
}

int NTPClient::getDayOfMonth() const {
time_t rawtime = this->getEpochTime() ;
struct tm * ti;
ti = localtime (&rawtime);
return ti->tm_mday; // day of month
}

int NTPClient::getHours() const {
return ((this->getEpochTime() % 86400L) / 3600);
}
Expand Down Expand Up @@ -207,4 +215,4 @@ void NTPClient::sendNTPPacket() {
void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {
randomSeed(analogRead(0));
this->_port = random(minValue, maxValue);
}
}
1 change: 1 addition & 0 deletions NTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class NTPClient {
bool forceUpdate();

int getDay() const;
int getDayOfMonth();
int getHours() const;
int getMinutes() const;
int getSeconds() const;
Expand Down