codescracker


c

C mktime()



« Previous Function Next Function »


mktime()

The mktime() function returns the calendar-time equivalent of the broken-down time found in the structure pointed to by time. The elements tm_wday and tm_yday are set by the function, so they need not be defined at the time of the call.

If mktime() cannot represent the information as a valid calendar time, -1 is returned.

mktime() Syntax

Following is the syntax of the mktime() function :

#include<time.h>
time_t mktime(struct tm *time);

mktime() Example

Following program tells you the day fo the week for January 3, 2005 :

#include<time.h>
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	
	struct tm t;
	time_t t_of_day;
	t.tm_year = 2005-1900;
	t.tm_mon = 0;
	t.tm_mday = 3;
	t.tm_hour = 0;   /* hour, min, sec don't matter */
	t.tm_min = 0;    /* as long as they don't cause a */
	t.tm_sec = 1;	 /* new day to occur */
	t.tm_isdst = 0;
	
	t_of_day = mktime(&t);
	printf(ctime(&t_of_day));
	
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test