Solution for Exercise 21-7
ex2107
#include <stdio.h> #include <time.h> int main() { time_t tictoc; struct tm *today; time(&tictoc); today = localtime(&tictoc); printf("It's now %d:%02d:%02d\n", today->tm_hour, today->tm_min, today->tm_sec); return(0); }
Output
It's now 16:53:26
Notes
* Output is in 24-hour format. The time above is 4:53:26 PM.
* The placeholder %02d
specifies decimal integer output, two-digits wide, with a leading zero if needed.
Copyright © 1997-2024 by QPBC.
All rights reserved