mktime



defined in header file time.h

time_t mktime( struct tm * tm_ptr);

The mktime() function converts tm structure to time_t as local time.

The value in the tm_isdst field informs mktime() function to consider day light saving time (DST) for the time supplied in the tm_ptr.

The mktime() function modifies the supplied tm_ptr for fields tm_wday (day of the week) and tm_yday (day in the year) and sets the values according to the values in other fields.

/*tm structure */
struct tm 
{
	int tm_sec;         /* seconds */
	int tm_min;         /* minutes */
	int tm_hour;        /* hours */
	int tm_mday;        /* day of the month */
	int tm_mon;         /* month */
	int tm_year;        /* year */
	int tm_wday;        /* day of the week */
	int tm_yday;        /* day in the year */
	int tm_isdst;       /* daylight saving time */
};

Parameters
ParameterDescription
tm_ptrpointer to tm instance with local calendar time to convert.
Returns

time_t value corresponding to the calendar time (struct tm) passed as argument. on error, it returns -1.


example program

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* memset */

//  gcc -o mktime_prg mktime_prg.c
// ./mktime_prg
int main () 
{
	printf("started program %s-%d\n", __FUNCTION__, __LINE__);
	
	struct tm tm_data;
	memset( &tm_data, 0, sizeof(struct tm));
	
	tm_data.tm_year = 2019 - 1900;
	tm_data.tm_mon = 3 - 1;
	tm_data.tm_mday = 19;
	tm_data.tm_hour = 11;
	tm_data.tm_min = 13;
	tm_data.tm_sec = 45;
   
	time_t time = mktime( &tm_data);
	
	printf(" time=%ld \n day-of-the-week=%d \n day-in-the-year=%d \n", time, tm_data.tm_wday, tm_data.tm_yday);
	
	return EXIT_SUCCESS;
}

program output

started program main-10
time=1552974225
day-of-the-week=2
day-in-the-year=77



strtok

Split string into tokens

posted on 2019-03-17 20:41:48 - C Programming Language Tutorials


zalloc

zalloc is a third party library

posted on 2018-12-12 20:46:30 - C Programming Language Tutorials


math

posted on 2017-12-29 22:52:47 - C Programming Language Tutorials


Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials