localtime Function

Converts a value to the local time.

Include

<time.h>

Prototype

struct tm *localtime(const time_t *tod);

Argument

tod
pointer to stored time

Return Value

Returns the address of the time structure.

Remarks

By default, the MPLAB XC16 compiler returns the time as instruction cycles. With this default, localtime and gmtime will be equivalent, except localtime will return tm_isdst (Daylight Savings Time flag) as -1 to indicate that the status of Daylight Savings Time is not known.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  time_t timer;
  struct tm *newtime;

  timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */

  newtime = localtime(&timer);
  printf("Local time = %s\n", asctime(newtime));
}

Example Output

Local time = Mon Oct 20 16:43:02 2003