Hallöchen!
Ich wollte Fragen, wie ich, wenn ich die NTP-Zeit abgerufen habe auf das aktuelle Datum komme.
Ich habe einige Beispiele gefunden, bei denen z.b. der Wochentag ausgespuckt wird und/oder die Uhrzeit, aber wie berechne ich das aktuelle Datum?
Was ich habe ist folgendes:
Seconds since Jan 1 1900 = 3568212589
Unix time = 1359223789
DayCount = 15731
Day of week = SAT
The UTC time is 18:09:49
Leider fehlt da das Datum =/
Die Berechungen dazu sehen aus dem Beispiel wie folgt aus:
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print(F("Seconds since Jan 1 1900 = " ));
Serial.println(secsSince1900);
// now convert NTP time into everyday time:
Serial.print(F("Unix time = "));
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);
unsigned long dayCount = epoch / 86400UL;
Serial.print(F("DayCount = "));
Serial.println(dayCount);
Serial.print(F("Day of week = "));
Serial.println(weekday[dayCount%7UL]);
// print the hour, minute and second:
Serial.print(F("The UTC time is ")); // UTC is the time at Greenwich Meridian (GMT)
Serial.print(((epoch % 86400L) / 3600)+1); // print the hour (86400 equals secs per day)
Serial.print(':');
if ( ((epoch % 3600) / 60) < 10 ) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(':');
if ( (epoch % 60) < 10 ) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
Serial.println(epoch %60); // print the second
}
Vieles Danke
LG
Chris