C Programming Language |
malloc |
calloc |
memset |
memcpy |
memory |
strcpy |
string |
strtok |
isalnum |
cctype |
errno |
cfenv |
clock |
difftime |
mktime |
ctime |
fprintf |
fscanf |
printf |
scanf |
stdio |
math |
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 */
};
Parameter | Description |
---|---|
tm_ptr | pointer to tm instance with local calendar time to convert. |
time_t value corresponding to the calendar time (struct tm) passed as argument. on error, it returns -1.
#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;
}
started program main-10
time=1552974225
day-of-the-week=2
day-in-the-year=77
zalloc is a third party library
posted on 2018-12-12 20:46:30 - C Programming Language Tutorials
posted on 2017-12-29 22:52:47 - C Programming Language Tutorials