get the current time in C

Posted by Antrromet on Stack Overflow See other posts from Stack Overflow or by Antrromet
Published on 2011-02-28T12:27:23Z Indexed on 2013/10/31 9:54 UTC
Read the original article Hit count: 173

Filed under:
|
|
|

I want to get the current time of my system. For that i'm using the following code in C.

time_t now;
struct tm *mytime = localtime(&now); 
if ( strftime(buffer, sizeof buffer, "%X", mytime) )
    {
    printf("time1 = \"%s\"\n", buffer);
    }

But the problem of this code is that its giving some random time.Also the random time is different all the time.I want the current time of my system. Can anyone please tell me how to solve this issue?

© Stack Overflow or respective owner

Related posts about c

    Related posts about time