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);
}
The problem is that this code is giving some random time. Also, the random time is different everytime. I want the current time of my system.
guys i got a new way get system time. though its lengthy and is full of silly works but in this way you can get system time in integer format.
guys you can use this function to get current local time. if you want gmtime then use gmtime function instead of localtime. cheers
Easy way:
Initialize your
now
variable.The
localtime
function is used to convert the time value in the passedtime_t
to astruct tm
, it doesn't actually retrieve the system time.