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.
Copy-pasted from here:
(just add "void" to the main() arguments list in order for this to work in C)
To extend the answer from @mingos above, I wrote the below function to format my time to a specific format ([dd mm yyyy hh:mm:ss]).
More information about
struct tm
can be found here.