6.22.10 localtime Function

Converts a value to the local time.

Attention: Local time zones are not supported by any compiler, and GMT is assumed.

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

As time zones are not supported, the localtime() function will return the same time as gmtime().

By default, both the MPLAB XC16 and XC-DSC compilers 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