Format
#include <time.h> struct tm *localtime(const time_t *timeval);
Language Level: ANSI, POSIX, XPG4
localtime breaks down timeval, corrects for the local
time zone and Daylight Saving Time, if appropriate, and stores
the corrected time in a structure of type tm.
The time value is usually obtained by a call to the time function.
Notes:
On both OS/2 and Windows, the time and date functions begin at 00:00:00 Universal Coordinate Time, January 1, 1970, and do not have an upper limit.
Return Value
localtime returns a pointer to the structure result.
If unsuccessful, it returns NULL.
Example
This example queries the system clock and displays the
local time.
#include <time.h> #include <stdio.h>
int main(void)
{
struct tm *newtime;
time_t ltime;
time(<ime);
newtime = localtime(<ime);
printf("The date and time is %s", asctime(newtime));
return 0;
/****************************************************
The output should be similar to:
The date and time is Wed Oct 31 15:00:00 1995 ****************************************************/ }
![]()
asctime -- Convert Time to Character
String
ctime -- Convert Time to Character
String
gmtime -- Convert Time
mktime -- Convert Local Time
setlocale -- Set Locale
time -- Determine Current Time
<locale.h>
<time.h>