I am using the following program to print the current time
int main()
{
printf("%s",__TIME__);
return 0;
}
It works only for the first time. If I run it after sometime it again gives the same old time.
Why do I need to do to refresh the time ?
__TIME__
is a standard predefined macro that expands to a string constant that describes the time at which the preprocessor is being run.
It is replaced by the preprocessor just before the compilation. So it does not change with different runs. But if you recompile your program you'll see the change.
To get the current time of the day you can use the time
, localtime
and asctime
functions as:
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With