Skip to content
Related Articles

Related Articles

time.h localtime() function in C with Examples
  • Last Updated : 07 Nov, 2019

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.

Syntax:

tm* localtime(const time_t* t_ptr);

Parameter: This function accepts a parameter t_ptr which represents the pointer to time_t object.

Return Value: This function returns a pointer to a struct tm object.

Below program illustrate the localtime() function in C:






// 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: %s\n",
           asctime(local));
  
    return 0;
}
Output:
Local time and date: Mon Sep 23 08:25:53 2019

Note: To understand this function clearly, change the time and date of your computer system and run the code again.

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.

My Personal Notes arrow_drop_up
Recommended Articles
Page :