Strftime giving wrong minutes

Here is the code

time_t ChronosClass::tmConvert_t(int YYYY, int MM, int DD, int hh, int mm, int ss) {
    struct tm t;
    t.tm_year = YYYY - 1900;
    t.tm_mon = MM - 1;
    t.tm_mday = DD;
    t.tm_hour = hh;
    t.tm_min = mm;
    t.tm_sec = ss;
    t.tm_isdst = 0;
    time_t t_of_day = mktime(&t);
    //Serial.println((Time.format(t_of_day, TIME_FORMAT_DEFAULT)));
    return t_of_day;
}

void ChronosClass::triggerValue(time_t value) {
    struct tm *tmNow;
    tmNow = localtime(&value);
    char buf[32];
    strftime(buf, sizeof(buf), "%Y-%m-%d %H:%m:%S", tmNow);
    Serial.printlnf("strftime=%s", buf);   
    Serial.printlnf("time=%ld", value);
    
}

and here is the output

The time was supposed to read 15:20 and not 15:01. The time_t value calculates to the correct date and time but with strftime i am getting wrong minutes.

Anyone know why?

Why not just use the Particle Time class?

1 Like

%m is month of the year. %M is the minute.

I tried but using Time.format on the time_t value obtained by mktime adds the timezone twice.

I just caught that also while looking at strfime online. Interestingly this code was a copy paste of one of your old posts.