从哪天哪时开始?

解决方案 »

  1.   

    例子:
    #include <time.h>
    #include <stdio.h>void main( void )
    {
       struct tm when;
       time_t now, result;
       int    days;   time( &now );
       when = *localtime( &now );
       printf( "Current time is %s\n", asctime( &when ) );
       printf( "How many days to look ahead: " );
       scanf( "%d", &days );   when.tm_mday = when.tm_mday + days;
       if( (result = mktime( &when )) != (time_t)-1 )
          printf( "In %d days the time will be %s\n", 
                  days, asctime( &when ) );
       else
          perror( "mktime failed" );
    }
    OutputCurrent time is Tue May 03 12:45:47 1994How many days to look ahead: 29
    In 29 days the time will be Wed Jun 01 12:45:47 1994
      

  2.   

    time_t time( time_t *timer );
    The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970