How to convert from struct tm to long int in C?

This is a simple question ... is there a way to convert struct tm ct;to a long integer? this is what my code looks like:

struct tm ct;
    scanf("%d", &ct.tm_sec);
    scanf("%d", &ct.tm_min);    
    scanf("%d", &ct.tm_hour);
    scanf("%d", &ct.tm_mday);
    scanf("%d", &ct.tm_mon);
    scanf("%d", &ct.tm_year);
+3
source share
2 answers

You can use the function mktime()to convert struct tmto time_t, which is an integer value.

+11
source

you want to get time_t, which represents the number of seconds since 01/01/1970 00:00:00

use mktime ():

time_t mktime (struct tm * timeptr);

http://www.cplusplus.com/reference/clibrary/ctime/mktime/

0
source

All Articles