cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : ctime (time.h) : localtime
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
ctime (time.h)
functions:
· asctime
· clock
· ctime
· difftime
· gmtime
· localtime
· mktime
· strftime
· time
macros:
· CLOCKS_PER_SEC
· NULL
types:
· clock_t
· size_t
· time_t
· struct tm

-

localtime function
struct tm * localtime ( const time_t * timer );
<ctime>

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 <stdio.h>
#include <time.h>

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 2000 

See also

asctime Convert tm structure to string (function)
ctime Convert time_t value to string (function)
gmtime Convert time_t to tm as UTC time (function)
mktime Convert tm structure to time_t (function)
time Get current time (function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us