how to display time in c code example
Example 1: measure time in c
void timeWait (float threshold) {
float timeInitial, timeMeasured, timeDelta = 0;
timeInitial = (float)clock();
while (timeDelta < threshold) {
timeMeasured = (float)clock();
timeDelta = ((timeMeasured - timeInitial) / (float)CLOCKS_PER_SEC);
}
printf("%.2f - %.2f s have passed.", threshold, timeDelta);
}
Example 2: c get time
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
return 0;
}