Thursday, April 10, 2008

Usage of localtime()

struct tm * localtime ( const time_t * timer );

Convert time_t to tm as local time

Uses the time pointed by timer to fill a tm structure with the values that represent the corresponding local time.

Parameters

timer
Pointer to a time_t value representing a calendar time (see time_t).

Return Value

A pointer to a tm structure with the time information filled in.

This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the contents of this structure is overwritten.

Example

/* localtime example */
#include
#include

int main ()
{
time_t rawtime;
struct tm * timeinfo;

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

return 0;
}

Output:

Current local time and date: Sat May 20 17:36:17 २०००


But be cautious while using the localtime() and gmtime() Usage because these functions will share common structure to give output
if these functions are used in Parallel result may unpredicted..



No comments: