ESP8266_Time gives wrong month

What might be wrong with this example?
Gives me month 2 instead of 3.
Also changing timezone does not do anything.
3rd question; does <time.h> do something here?
If i remove it, code still works except those i mentioned above.
And yes, i'm not expert.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <time.h>
#include "timezone.h"

const char *WIFI_NETWORK_NAME = "***"; // Change to your wifi network name
const char *WIFI_PASSWORD = "*****";      // Change to your wifi password

const char *TIME_SERVER = "pool.ntp.org";
int myTimeZone = EET; // change this to your time zone (see in timezone.h)

time_t now;

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

  WiFi.begin(WIFI_NETWORK_NAME, WIFI_PASSWORD);

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

  configTime(myTimeZone, 0, TIME_SERVER);

  while (now < EPOCH_1_1_2019)
  {
    now = time(nullptr);
    delay(500);
    Serial.print("*");
  }
}

// toStringAddZero()
// this function adds a zero to a date string if its a single digit
// for example if data = 1, then the function will return 01
// this makes the date and time string's consistant size for display
String toStringAddZero(int data)
{
  String st = "";
  if (data < 10)
  {
    st = "0" + String(data);
  }
  else
  {
    st = String(data);
  }
  return st;
}

void loop()
{
  
  struct tm *timeinfo;

  time(&now);
  timeinfo = localtime(&now);
Serial.println(now);
delay(400);
  int year = timeinfo->tm_year + 1900;
  int month = timeinfo->tm_mon;
  int day = timeinfo->tm_mday;
  int hour = timeinfo->tm_hour;
  int mins = timeinfo->tm_min;
  int sec = timeinfo->tm_sec;
  int day_of_week = timeinfo->tm_wday;

  Serial.print("Date = " + toStringAddZero(day) + "/" + toStringAddZero(month) + "/" + String(year));
  Serial.println(" Time = " + toStringAddZero(hour) + ":" + toStringAddZero(mins) + ":" + toStringAddZero(sec));
  Serial.print("Day is " + String(DAYS_OF_WEEK[day_of_week]));
  Serial.println(" or " + String(DAYS_OF_WEEK_3[day_of_week]));
  
  delay(1000);
}
const float GMT = 0;
const float UTC = 0;
const float ECT = 1.00;
const float EET = 2.00;
const float ART = 2.00;
const float EAT = 3.00;
const float MET = 3.30;
const float NET = 4.00;
const float PLT = 5.00;
const float IST = 5.30;
const float BST = 6.00;
const float VST = 7.00;
const float CTT = 8.00;
const float JST = 9.00;
const float ACT = 9.30;
const float AET = 10.00;
const float SST = 11.00;
const float NST = 12.00;
const float MIT = -11.00;
const float HST = -10.00;
const float AST = -9.00;
const float PST = -8.00;
const float PNT = -7.00;
const float MST = -7.00;
const float CST = -6.00;
const float EST = -5.00;
const float IET = -5.00;
const float PRT = -4.00;
const float CNT = -3.30;
const float AGT = -3.00;
const float BET = -3.00;
const float CAT = -1.00;

const int EPOCH_1_1_2019 = 1546300800; //1546300800 =  01/01/2019 @ 12:00am (UTC)
const char *DAYS_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char *DAYS_OF_WEEK_3[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

It's still March where I am, so 2 would be correct.

Values might be zero-based meaning that january = 0: https://www.cplusplus.com/reference/ctime/tm/

Thanks. That did not come into my mind because this is an example so I thought it works. Also everything else works fine.
Except the time zone. Any ideas for that, please.
I fixed this the way I do not like very much, just add two hours (+2).

Try this:

  //time(&now);
  //timeinfo = localtime(&now);
  getLocalTime(&timeinfo)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.