-1

I'm using a NTP server in my Arduino code and ESP8266 board. I'm using "Serial.println(timeClient.getFormattedTime());" but the function print only the time not the date ( DD-MM-YYYY ) and i need the date..

This is my code:

#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>

const char *ssid     = "----------";
const char *password = "**********";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

void setup(){
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
}

void loop() {
  timeClient.update();
  Serial.println(timeClient.getFormattedTime());
  delay(1000);
}

Thanks

1 Answers1

0

If you look at the source code for that library you'll see that is all the getFormattedtime function is supposed to output.

I don't see a function in that library for the date. It looks to me like you'll have to get the epoch time with getEpochTime and calculate the date yourself. There should be lots of examples on the internet of how to convert epoch time to a date.

The Time library has functions to convert from unix time to month day and year.

Delta_G
  • 2,927
  • 2
  • 9
  • 15