Simple issue with TimeAlarms I need help with parsing time.

I’m pretty sure it is down to me only working on programming for a few weeks now.
So I am still a total fool and have on a few times created problems for myself that were not needed and simple to fix once understood… retlating to
#include <TimeLib.h>
#include <TimeAlarms.h>

I love the arduino IDE, I have sketch that I am having problems with. The unit saves ssid and password to the eeprom and starts up automatically and connects to the internet. (just using snippets of other people’s code)
All that works fine and I can even connect to NTP server and display time on an oled…
But I I stumped by a simple line in the timeAlarms sketch.

setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011  //this is the line I don't now how to write.

I can not seem to get this data completed automatically… I have even done formatting of the time… and it pints out as the correct 6 numbers and comas on the serial if asked but I can not get the line of code correct to set time to the current time.

I’m only posting partial sketch but I’m pretty sure that the problem lies here… As is it connects to the internet and displays time to the OLED, but time printed to the Serial from timealarms is from 00:00:00 each time it starts and never syncs up.
even when I tried formatting it like this

String get_time3(){
 time_t now;
 time(&now);
 char time3_output[30];
 // See http://www.cplusplus.com/reference/ctime/strftime/ for strftime functions
 strftime(time3_output, 30, "%H,%M,%w,%d,%m,%y", localtime(&now)); // "%H,%M,%w,%d,%m,%y" goal
 return String(time3_output); // 
 //Serial.println(get_time2());
 }

I can’t seem to get this value placed after SetTime in the line of code below…
If I can get this time to track the time on the OLED, my problems would be solved… at least until my RTC arrives… (I only heard of those last week)

  ...WiFi.begin(esid.c_str(), epass.c_str());  //connects to wifi just fine
configTime(0, 0,   "za.pool.ntp.org", "time.nist.gov"); //"za.pool.ntp.org",
 // See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
 setenv("TZ", "SAST-2", 1); //displays correct time on oled

delay(15000); 

Serial.println(F("wifi connected"));
Serial.println(get_time());
Serial.println(get_dom());

}

String get_time(){
 time_t now;
 time(&now);
 char time_output[6];
 // See http://www.cplusplus.com/reference/ctime/strftime/ for strftime functions
 strftime(time_output, 6, "%R", localtime(&now)); 
 return String(time_output); // returns  12:31:45
//Serial.println(get_time());
 }

Just partial code but just wanted to show how I have been getting my time…
I just dont know how to edit the line that sets the time for the timealarm, and it has been 3 days now!

Happy new year to everyone else fighting code rather than hangover this morning.

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

Thank you, leave it to me to mess up my hello world message!

I'm only posting partial sketch but I'm pretty sure that the problem lies here...

... how many countless times someone has claimed that?...

Please post the entire sketch.

setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011  //this is the line I don't now how to write.

This function requires 6 parameters, each of them integers. Is that what you are using as parameters in your sketch or are they perhaps Strings of characters representing the integers ?

Post the complete sketch and we may be able to help

I use string format time command strftime so I guess it is a string...
I am still at the beginner level and trip myself up with things like this a lot.
I put in every permutation of setTimeXXX I could think of.
Looks like I first need to change the date type somehow.

the string then get s "fed" to a Char if I understand correctly...

char time3_output[30];// See http://www.cplusplus.com/reference/ctime/strftime/ for strftime functions

 strftime(time3_output, 30, "%H,%M,%w,%d,%m,%y", localtime(&now)); //%H,%M,%w,%d,%m,%y" goal

 return String(time3_output); //

I thought it would be as simple as = time_output3()

It's entirely possible - let us know how it turns out...

The time library function setTime() has two flavors.

setTime(int hr,int min,int sec,int dy, int mnth, int yr)
setTime(time_t t)

You should be able to directly pass in the time_t timestamp without going through any conversion.

cattledog:
The time library function setTime() has two flavors.

setTime(int hr,int min,int sec,int dy, int mnth, int yr)

setTime(time_t t)




You should be able to directly pass in the time_t timestamp without going through any conversion.

What goes into the t and time_t in the line above.?
I tried setTime(time_t t); but it complained about the second t

I saw the library sets up hour, month, day, etc. up as int.

So inside the sketch, I changed the one function get_hournow()

String get_hournow(){
  time_t now;
  time(&now);
  char hournow_output[30];
  
    strftime(hournow_output, 30, "%H", localtime(&now)); // "%H,%M,%w,%e,%m,%y" goal
    return String(hournow_output); // 
   }

this returns the correct hour when I print to serial....

I found the bit that prints the wrong time to the serial port.
Inside the sketch there ir this bit... the indented bits are some of my own attempts to get hour() = get_hournow()
I even tried converted to integer using

(get_hournow().toInt());

once again this returns the correct value as an integer, but I am stumed at simply getting setTime to work correctly.

What goes into the t and time_t in the line above.?
I tried setTime(time_t t); but it complained about the second t

time_t is a uint32_t variable. It is used containing the time stamp of seconds since the start of the epoch used. TimeLib.h may use seconds since Jan 01 2000.

For example

time_t t; //declare the variable
t = 1609610988; //give it a value
setTime(t); //pass it to the function