Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"round" time_t to day/hour?

Tags:

c

time

I have a unix time_t , is there any easy way to convert this to a time_t so it:

  1. Represents midnight of the day of the time_t ?
  2. Represents the start of the hour of the time_t ?

1 Answers

Something like this:

time_t t = time(NULL);

t -= (t % 86400); 

The constant 86400 = 24 * 60 * 60 - a useful number to remember, I think... ;)

like image 140
Mats Petersson Avatar answered Sep 02 '25 16:09

Mats Petersson