How to convert time to integer..?

I am using the ESP32 with Time.h library from the examples SimpleTime to pull time from the internet.
The library returns time in the format
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
My target is to pick either hours %H, minutes %M or seconds %S and put it into an integer like
int T_H
int T_M
int T_S

How do I do that..?

My main purpose of doing it is to do some certain job when the hour, minute or seconds changes or do something at a certain specified time.

Why not simply use the values from the timeinfo structure ?

tm_hour
tm_min
tm_sec
1 Like

Use following.

timeinfo.tm_sec
timeinfo.tm_min
timeinfo.tm_hour

ex.

  if ((timeinfo.tm_hour == 12) && (timeinfo.tm_min == 0))
  {
    Serial.println("LUNCH TIME!!!!!!!!!!!!!");
  }
2 Likes

Ahh.. Thank you so much for the information guix & chrisknightley I didn't know that.
Where can I get these details of any library..?

cpp standards?
https://en.cppreference.com/w/c/chrono/tm

2 Likes

In this case it's a bit different from most libraries you may come across. Usually if you include a library, there's a library folder with a .h file and all the method definitions in it. However, in this case, time.h is part of the set of standard libraries that come with the C compiler that's used. @chrisknightley has linked you to an excellent source for the documentation.

1 Like

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