mktime - C time.h

C examples for time.h:mktime

type

function

From


<ctime>
<time.h>

Description

Convert tm structure to time_t

Prototype

time_t mktime (struct tm * timeptr);

Parameters

Parameter Description
timeptr Pointer to a tm structure.

Return Value

A time_t value corresponding to the calendar time passed as argument.

On error, a value of -1 is returned.

Demo Code


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

int main ()/* w ww.j av a  2 s  .co  m*/
{
  time_t rawtime;
  struct tm * timeinfo;
  int year, month ,day;
  const char * weekday[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

  year = 2020;
  month = 11;
  day = 23;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  timeinfo->tm_year = year - 1900;
  timeinfo->tm_mon = month - 1;
  timeinfo->tm_mday = day;

  mktime ( timeinfo );

  printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]);

  return 0;
}

Related Tutorials