time.h localtime() function in C
The localtime() function is defined in the time.h header file. The localtime( ) function return the local time of the user i.e time present at the task bar in computer.
Here is how it's syntax looks:
tm* localtime(const time_t* t_ptr);
localtime() function accepts a parameter t_ptr which represents the pointer to time_t object and it returns a pointer to a struct tm object.
Here is a program to implement it.
// C program to demonstrate
// example of localtime() function.
#include <stdio.h>
#include <time.h>
int main()
{
struct tm* local;
time_t t = time(NULL);
// Get the localtime
local = localtime(&t);
printf("Local time and date is: %s\n",
asctime(local));
return 0;
}
Local time and date is: Sun Dec 22 18:10:53 2019
If you'll change the time of your local computer, it will change.