NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

Added two new methods to return Date and Time as a struct and get formatted Date Time string with a given format

Open isharasampath opened this issue 5 years ago • 12 comments
trafficstars

Added bellow two methods to return Date and Time information together as a struct and formatted datetime string with a given format.

  • getDateTime
  • getFormattedDateTime

Additional context

Additional requests

  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-1126950276
  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-1128466438
  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-1259850449
  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-1296254495
  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-1509963424
  • https://github.com/arduino-libraries/NTPClient/pull/94#issuecomment-2495481476

isharasampath avatar Mar 18 '20 12:03 isharasampath

Please add the new function names to keywords.txt, using a true tab as a separator between the keyword and the identifier: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywordstxt-format

Added new two methods to the keywords.txt

isharasampath avatar Mar 19 '20 13:03 isharasampath

Thanks for the review and the comments. Do we know when these changes going to merge and will be publicly available ?

isharasampath avatar Mar 20 '20 11:03 isharasampath

Hello, is it possible to add this possiblility ? in NTPClient.h /** * Return the date time from the epochtime value as a String with the given format (Ex: %Y/%m/%d %H:%M:%S) */ String getFormattedDateTime(const char* dateTimeFormat, time_t t) const;

in NTPClient.cpp String NTPClient::getFormattedDateTime(const char* dateTimeFormat, time_t t = 0) const { struct tm * ts; time_t rawTime = t ? t : this->getEpochTime(); ts = localtime(&rawTime); char buf[64]; strftime(buf, sizeof(buf), dateTimeFormat, ts); return String(buf); }

that may be useful

zzuutt avatar Apr 23 '20 08:04 zzuutt

Hello, is it possible to add this possiblility ? in NTPClient.h /** * Return the date time from the epochtime value as a String with the given format (Ex: %Y/%m/%d %H:%M:%S) */ String getFormattedDateTime(const char* dateTimeFormat, time_t t) const;

in NTPClient.cpp String NTPClient::getFormattedDateTime(const char* dateTimeFormat, time_t t = 0) const { struct tm * ts; time_t rawTime = t ? t : this->getEpochTime(); ts = localtime(&rawTime); char buf[64]; strftime(buf, sizeof(buf), dateTimeFormat, ts); return String(buf); }

that may be useful

I think this is something more of a utility functions which NTPClient not directly involving. Passing epochtime from outside and getting it formatted is not part of a job in NTPClient.

isharasampath avatar Jun 24 '20 04:06 isharasampath

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 09 '21 13:04 CLAassistant

Would be nice if we could have this in.

'class NTPClient' has no member named 'getFormattedDate'; did you mean 'getFormattedTime'?

getFormattedDateTime method will return the formatted date, time or datetime string according to the given format.

Ex: datetime patter: %Y/%m/%d %H:%M:%S or %Y-%m-%d %H:%M:%S date pattern: %Y/%m/%d time pattern: %H:%M:%S

isharasampath avatar Dec 23 '21 05:12 isharasampath

will this enhancement be merged to main branch?

nona00 avatar May 15 '22 14:05 nona00

will this enhancement be merged to main branch?

I'm also waiting for the same

iabe2561 avatar May 17 '22 06:05 iabe2561

Not merged yet?

m4nzm333 avatar Sep 27 '22 17:09 m4nzm333

Is there any particular reason why that wasn't merged yet?

dawidadach avatar Oct 30 '22 13:10 dawidadach

Is anything holding back timeClient.getFormattedDateTime()?

probonopd avatar Apr 15 '23 20:04 probonopd