NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

Using getFormattedTime() to format a given time

Open sheffieldnikki opened this issue 7 years ago • 1 comments

I've adjusted getFormattedTime() to take an (optional) 'secs' argument, so that the same formatting code can be used to format any given time, while still formatting the NTP time if the argument is left out. This is similar to time conversion functions in other languages, and might avoid the need to include a dedicated time/date library in some projects.

NTPClient.h:

/**
 * @return secs argument (or 0 for current time) formatted like `hh:mm:ss`
 */
String getFormattedTime(unsigned long secs = 0);

NTPClient.cpp:

String NTPClient::getFormattedTime(unsigned long secs) {
  unsigned long rawTime = secs ? secs : this->getEpochTime();

sheffieldnikki avatar Apr 24 '17 21:04 sheffieldnikki

This is great! I was suprised to realize that this simple function wasn't pulled so far? I'm using the frok from @taranais now! kudos

seikobu avatar Feb 28 '21 16:02 seikobu

Hi @sheffieldnikki. Thanks for taking the time to submit an issue.

I see we have another report about this at https://github.com/arduino-libraries/NTPClient/issues/3.

It is best to have only a single issue per subject so we can consolidate all relevant discussion to one place, so I'll go ahead and close this in favor of the other.

If you end up with additional information to share, feel free to comment in the other thread.

per1234 avatar Jun 23 '24 13:06 per1234