localtime - C time.h

C examples for time.h:localtime

Type

function

From


<ctime>
<time.h>

Description

Convert time_t to tm as local time

Prototype

struct tm * localtime (const time_t * timer);

Parameters

Parameter Description
timer a time value in type time_t.

Return Value

tm structure in the local time representation of timer.

Demo Code


#pragma warning(disable:4996)//w w  w . j  a va 2s.  c o  m
#define _CRT_SECURE_NO_WARNINGS
#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;
}

Related Tutorials