I want to set a time_t variable to the next date/time at 10pm. So for example, if it was 11pm it would set the time_t to the 10pm the next day (23 hours later) or if it was 5pm it would set it to 10pm (in 5 hours).
I can think of a number of ways to do this (such as calculating the seconds until the next 10pm and adding that value), but they all feel like rather a hackish approach. What’s the best way to accomplish this?
Convert it to a
struct tm, usinglocaltimefor example. If it’s past 10pm, add one day. Set hour to 10pm.Convert back to
time_tusingmktime.