How to get time since epoch in seconds with C

2 Answers

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

int main(void)
{
    struct timespec ts;
    
    timespec_get(&ts, TIME_UTC);

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




/*
run:

Time since epoch: 1676041889 seconds

*/

 



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

int main(void)
{
    time_t seconds;

    seconds = time(NULL);

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




/*
run:

Time since epoch: 1676042147 seconds

*/

 



answered Feb 10, 2023 by avibootz

Related questions

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