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 125 views
2 answers 147 views
147 views asked Feb 10, 2023 by avibootz
2 answers 457 views
2 answers 159 views
1 answer 137 views
...