C localtime function returns the local time

Syntax

C localtime function has the following format.

struct tm *localtime(const time_t *time);

C localtime function is from header file time.h.

Description

C localtime function returns local time.

Example

Use C localtime function to get the local time.


#include <time.h>
#include <stdio.h>
/*  www  .  ja v a 2 s.c  om*/
/* Print local and UTC time. */
int main(void)
{
  struct tm *local;
  time_t t;

  t = time(NULL);
  local = localtime(&t);
  printf("Local time and date: %s\n", asctime(local));
  local = gmtime(&t);
  printf("UTC time and date: %s\n", asctime(local));

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h