#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main( void ) {
struct timeval now;
struct tm *curr_time;
gettimeofday(&now, 0);
curr_time = localtime(&now.tv_sec);
printf("Roughly %d hours until 5pm tomorrow!\r\n", (17-curr_time->tm_hour)+24);
return 0;
}
/* a little extra (naive) logic */
if (curr_time->tm_hour < 17) {
printf("Roughly %d hours until 5pm today!\r\n", (17-curr_time->tm_hour));
} else if (curr_time->tm_hour == 17) {
printf("It's 5pm!\r\n");
} else {
printf("Roughly %d hours until 5pm tomorrow!\r\n", (17-curr_time->tm_hour)+24);
}
I was working on using mktime to do this, but then realized mktime asks for a specific month and day and I need to make it be every day. Then I figured I could use date() in mktime, but then realized I couldn't just do +1 on the day in case it's the end of the month.
Easiest way to do this?