From HH:MM to seconde past midnight

Hello,

I am getting moon rise and moon set from a http client in this format : HH:MM

For my project I will need to change this time in second past midnight.

Do you have any suggestion ?

Thanks,
Théo

Do you have any suggestion ?

I assume that if you got HH and MM as integers then you could calculate the number of seconds. Is the conversion where you are stuck ?

Thanks for your quick response

I can obviously do it by hand but I basically don t know how to write the code to get there..

Let say that I am learning coding micro-controller in unusual way.. Means that when it goes to basic I am lost and don t know which way to look to find simple example.

Leter on in my code I will have to convert from unix timestamp to YYYYMMDD. I made some research and i guess I will have to use GitHub - PaulStoffregen/Time: Time library for Arduino

Thanks for your help.

Let's start with the basics.

Do you have HH and MM as separate variables in your program and if so, what sort of variables are they ?

It would help if you posted your program but before you do please read this before posting a programming question and follow the advice about formatting code and using code tags when you post it

HH:MM are separate constant in my program (const char*).

Attached my program so far (made for ESP 8266).
In block comment where I expect to convert the time format.

Thanks,
Théo

IML_V7_forum.ino (2.25 KB)

const char* moonRise = "05:23";
const char* moonSet = "17:11";

int32_t secondsFromHoursMinutes(const char* from) {
  return (atoi(from) * 60L + atoi(from + 3)) * 60;
}

void setup() {
  Serial.begin(250000);
  int32_t dsRise = secondsFromHoursMinutes(moonRise);
  int32_t dsSet = secondsFromHoursMinutes(moonSet);
  Serial.println(dsRise);
  Serial.println(dsSet);
  if (dsSet < dsRise) {
    dsSet += 24 * 60 * 60L;
  }
  int32_t dsDuration = dsSet - dsRise;
  Serial.print("duration ");
  Serial.print(dsDuration);
  Serial.println(" seconds");
}
void loop() {}
19380
61860
duration 42480 seoonds

I basically don t know how to write the code to get there.

The Arduino is programmed in C/C++. There are many fine on line tutorials and books to show you how.

Perfect !
Thanks Whandall !

Théo