Answers for "convert calendar time to epoch in c programming"

C
0

convert calendar time to epoch in c programming

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

int main(void) {
    struct tm t;
    time_t t_of_day;

    t.tm_year = 2019-1900;  // Year - 1900
    t.tm_mon = 7;           // Month, where 0 = jan
    t.tm_mday = 8;          // Day of the month
    t.tm_hour = 16;
    t.tm_min = 11;
    t.tm_sec = 42;
    t.tm_isdst = -1;        // Is DST on? 1 = yes, 0 = no, -1 = unknown
    t_of_day = mktime(&t);

    printf("seconds since the Epoch: %ldn", (long) t_of_day);
}
Posted by: Guest on January-27-2022
0

convert calendar time to epoch in c programming

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

int main(void)
{
    time_t     now;
    struct tm  ts;
    char       buf[80];

    // Get current time
    time(&now);

    // Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
    ts = *localtime(&now);
    strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
    printf("%sn", buf);
    return 0;
}
Posted by: Guest on January-27-2022

Code answers related to "convert calendar time to epoch in c programming"

Code answers related to "C"

Browse Popular Code Answers by Language