How to get time since epoch in hours with C

2 Answers

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

int main(void)
{
    time_t seconds;

    seconds = time(NULL);

    printf("Time since epoch: %ld hours", seconds/3600);
}




/*
run:

Time since epoch: 465567 hours

*/

 



answered Feb 10, 2023 by avibootz
0 votes
#include <stdio.h>
#include <time.h>

int main(void)
{
    struct timespec ts;

    timespec_get(&ts, TIME_UTC);

    printf("Time since epoch: %ld hours", ts.tv_sec/3600);
}




/*
run:

Time since epoch: 465567 hours

*/

 



answered Feb 10, 2023 by avibootz

Related questions

1 answer 107 views
2 answers 130 views
130 views asked Feb 10, 2023 by avibootz
2 answers 443 views
2 answers 150 views
1 answer 118 views
...