#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 = "Wokwi-GUEST";
const char *password = "";
WiFiUDP ntpUDP;
int HOUR;
int MINUIT;
int Sec;
// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionally you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "in.pool.ntp.org", 19800);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
}
void loop() {
timeClient.update();
// Get the epoch time
unsigned long epochTime = timeClient.getEpochTime();
// Convert epoch time to tm struct
struct tm *ptm = gmtime((time_t *)&epochTime);
// Print the date in YYYY-MM-DD format
Serial.printf("Date: %04d-%02d-%02d\n", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday);
Serial.println(timeClient.getFormattedTime());
int HOUR = timeClient.getHours();
int MINUIT = timeClient.getMinutes();
int Sec = timeClient.getSeconds();
int YEAR = ptm->tm_year + 1900;
int MONTH = ptm->tm_mon + 1;
int DATE = ptm->tm_mday;
// HOUR = timeClient.getHour();
// MINUIT = timeClient.getMinutes();
// Sec = timeClient.getSecound();
Serial.print("HOUR:");Serial.println(HOUR);
Serial.print("MINUIT:");Serial.println(MINUIT);
Serial.print("Sec:");Serial.println(Sec);
Serial.print("YEAR:");Serial.println(YEAR);
Serial.print("MONTH:");Serial.println(MONTH);
Serial.print("DATE:");Serial.println(DATE);
delay(1000);
}