Timezones.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <ezTime.h>
  2. #include <WiFi.h>
  3. void setup() {
  4. Serial.begin(115200);
  5. while (!Serial) { ; } // wait for Serial port to connect. Needed for native USB port only
  6. WiFi.begin("your-ssid", "your-password");
  7. // Uncomment the line below to see what it does behind the scenes
  8. // setDebug(INFO);
  9. waitForSync();
  10. Serial.println();
  11. Serial.println("UTC: " + UTC.dateTime());
  12. Timezone myTZ;
  13. // Provide official timezone names
  14. // https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  15. myTZ.setLocation(F("Pacific/Auckland"));
  16. Serial.print(F("New Zealand: "));
  17. Serial.println(myTZ.dateTime());
  18. // Wait a little bit to not trigger DDoS protection on server
  19. // See https://github.com/ropg/ezTime#timezonedropnl
  20. delay(5000);
  21. // Or country codes for countries that do not span multiple timezones
  22. myTZ.setLocation(F("de"));
  23. Serial.print(F("Germany: "));
  24. Serial.println(myTZ.dateTime());
  25. // Same as above
  26. delay(5000);
  27. // See if local time can be obtained (does not work in countries that span multiple timezones)
  28. Serial.print(F("Local (GeoIP): "));
  29. if (myTZ.setLocation()) {
  30. Serial.println(myTZ.dateTime());
  31. } else {
  32. Serial.println(errorString());
  33. }
  34. }
  35. void loop() {
  36. events();
  37. }