How to use gmtime() to get the current calendar date and time in C

1 Answer

0 votes
#include <time.h>
#include <stdio.h>
 
int main(void)
{
    time_t t = time(NULL);
    
    printf("UTC:   %s", asctime(gmtime(&t)));
    printf("local: %s", asctime(localtime(&t)));
        
    return 0;
}

/*
run:
 
UTC:   Sun Aug 28 15:05:26 2016
local: Sun Aug 28 18:05:26 2016

*/

 



answered Aug 28, 2016 by avibootz

Related questions

1 answer 193 views
1 answer 87 views
87 views asked Jan 8, 2023 by avibootz
1 answer 112 views
1 answer 143 views
1 answer 109 views
...