2.1.8.35 time


Description

Get the number of seconds elapsed since midnight (00:00:00), January 1, 1970.

Syntax

time_t time( time_t * timer )

Parameters

[input] timer
Storage location for time

Return

time returns the time in elapsed seconds. There is no error return.

Examples

EX1

void time_ex1()
{
    time_t ltime;
    tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };
    char ampm[] = "AM";

    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value 
    // for the variable. 
    _tzset();
    int daylight;
    long timezone;
    char* tzname[2];
    get_time_setting(&daylight, &timezone, tzname);
    printf( "daylight = %d\n", daylight );
    printf( "timezone = %ld\n", timezone );
    printf( "tzname[0] = %s\n", tzname[0] );
    
    // Get UNIX-style time and display as number and string. 
    time( &ltime );
    printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );

    // Display UTC. 
    gmt = gmtime( &ltime );
    printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );
    
    // Convert to time structure and adjust for PM if necessary. 
    today = localtime( &ltime );
    if( today->tm_hour > 12 )
    {
       strcpy( ampm, "PM" );
       today->tm_hour -= 12;
    }
    if( today->tm_hour == 0 )  // Adjust if midnight hour. 
           today->tm_hour = 12;
    
    // Make time for noon on Christmas, 1993. 
    if( mktime( &xmas ) != (time_t)-1 )
           printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

    // Use time structure to build a customized time string. 
    today = localtime( &ltime );
}

Remark

The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock.

The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.

See Also

Header to Include

origin.h

Reference