C Reference function localtime()

Usage of localtime():

struct tm * localtime ( const time_t * ptr_time );

Parameters:

The pointer ptr_time is a pointer to a time_t object that contains a calendar time.

Return Value:

The function localtime() returns a pointer to a tm structure. The tm structure contains the time information.

Explanation:


The function localtime() uses the time pointed by the pointer ptr_time to fill a tm structure with the values that represent the corresponding local time.

The tm structure is statically allocated and shared by the functions gmtime and localtime. If either one of these functions is called, then the content of the structure tm is overwritten.

Source code example of localtime():


#include <stdio.h>
#include <time.h>

int main ()
{
	time_t time_raw_format;
	struct tm * ptr_time;

	time ( &time_raw_format );
	ptr_time = localtime ( &time_raw_format );
	printf ("Current local time and date: %s", asctime(ptr_time));

	return 0;
}

Output example of the program above:


	Current local time and date: Fri Jan 11 12:11:50 2008

This entry was posted in C Reference time.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.