Home >>C Time Library Function >C localtime() function

C localtime() function

C localtime() function

C localtime() function is used to convert the given time since epoch to calendar time which is expressed as local time. It uses the time pointed by timer to fill a tm structure with the values that represent the corresponding local time. This function is defined in <time.h> header file.

Syntax:
struct tm *localtime(const time_t *timer)

Parameters:-

timer− It is the pointer to a time_t value representing a calendar time.

Here is an example of localtime() function:

#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm *info;
time( &rawtime );
info = localtime( &rawtime );
printf("Current local time and date: %s", asctime(info));
return(0);
}

Output:
Current local time and date: Wed Apr 15 11:24:40 2020

No Sidebar ads