localtime -- Break Local Time Value into Components

SYNOPSIS

 #include <time.h>

 struct tm *localtime(const time_t *timep);
 

DESCRIPTION

localtime converts a time_t value to local time, separates it into components, and returns a pointer to a struct tm containing the results.

Under POSIX, localtime is affected by time-zone information contained in the TZ environment variable, if it is defined.

RETURN VALUE

localtime returns a pointer to the broken-down, local-time value. The pointer may be to static data, which may remain valid only until the next call to gmtime, localtime, or ctime.

CAUTION

The pointer returned by localtime may reference static storage, which may be overwritten by the next call to gmtime, localtime, or ctime.

DIAGNOSTICS

NULL is returned if local time is not available or if the argument value is not a valid time.

EXAMPLE

  #include <time.h>
  #include <stdio.h>

  main()
  {
     time_t timeval;
     struct tm *now;

     time(&timeval);
     now = localtime(&timeval);    /* Get current local time. */
     if (now->tm_mon == 0 && now->tm_mday == 1)
        puts("Happy New Year.");
  }

 

RELATED FUNCTIONS

gmtime, tzset

SEE ALSO

Timing Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.