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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles