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 210 views
1 answer 96 views
96 views asked Jan 8, 2023 by avibootz
1 answer 122 views
1 answer 153 views
1 answer 121 views
...