by Dinesh Thakur Category: Function and Pointer

The function localtime () converts the calendar time, i.e., the output of function time (), into a broken-down time expressed as local time, and returns the pointer to broken-down time. If the conversion into local time fails, the function returns NULL pointer. The prototype of the function is written in the following manner:

struct tm* localtime(const time_t *Time);

where the pointer Time is the output of function time (),such that

time_t time( time_t *Time);

Illustrates the application of function localtime

#include <stdio.h>

#include <time.h>
  time_t justnow;
  struct tm *Time;
  time (&justnow); II address of justnow
  Time= localtime(&justnow);
   /* Convert the calender time to local time and return a pointer to the struct tm */
  printf("%s", asctime(Time));
   /* asctime() converts the broken down time into a string of the form given in the output.*/

Function localtime () in C

Popular Article