- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
int
next_day( int mmdd )
{
struct tm time;
time_t clock;
int date;
int secs_in_day = 60 * 60 * 24;
/* convert date to mmdd if in yyyymmdd format */
if (mmdd > 9999)
mmdd = mmdd % 10000;
/* Get today's date/time in seconds since 1970 */
clock = time( NULL );
/* Loop until we obtain a clock time corresponding to the day passed in */
while ( 1 )
{
/* Get structure with filled in date/time info. for day corresponding to
* the clock value we're currently working on & construct date from that.
*/
localtime( &clock, &time );
date = (tm->tm_mon + 1) * 100 + tm->tm_mday;
if ( date > mmdd )
{
/* Set clock back to previous day */
clock -= secs_in_day;
continue;
}
/* Set clock forward to next day */
clock += secs_in_day;
if ( date < mmdd ) /* Date is in future */
continue;
tm = localtime( &clock );
date = (tm->tm_mon + 1) * 100 + tm->tm_mday;
return date; /* Next date after one passed in */
}
}
Функция, получает день в виде числа в формате mmdd, возвращает следующий день в текущем году в таком же формате.
Комментарии (0) RSS
Добавить комментарий