The 2nd answer in How do I convert "2012-03-02" into unix epoch time in C? does provides the solution. But it uses tm_yday instead of tm_mday and tm_mon of tm structure.
My Input is human readable date and time and the desired output is UNIX epoch time.
int main(int argc, char *argv[])
{
char timeString[80] = {"05 07 2021 00 33 51"}; //epoch is 1620347631000
struct tm my_tm = {0};
if(sscanf(timeString, "%d %d %d %d %d %d", &my_tm.tm_mon, &my_tm.tm_mday, &my_tm.tm_year, &my_tm.tm_hour, &my_tm.tm_min, &my_tm.tm_sec)!=6)
{
/* ... error parsing ... */
printf(" sscanf failed");
}
// In the below formula, I can't use my_tm.tm_yday as I don't have the value for it.
//I want to use my_tm.tm_mday and tm_mon.
printf("%d",my_tm.tm_sec + my_tm.tm_min*60 + my_tm.tm_hour*3600 + my_tm.tm_yday*86400 +
(my_tm.tm_year-70)*31536000 + ((my_tm.tm_year-69)/4)*86400 -
((my_tm.tm_year-1)/100)*86400 + ((my_tm.tm_year+299)/400)*86400 );
return EXIT_SUCCESS;
}
So, in other words, I'm looking for a replacement for my_tm.tm_yday*86400 in terms of my_tm.tm_mday and my_tm.tm_mon