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("Today is %d/%d/%d\n", today->tm_mon+1, today->tm_mday, today->tm_year+1900); return(0); }
Notes
* The localtime() function stuffs the tm
structure with values representing the current time — except for the month and year. The month value starts with 0 for January, so the tm_mon
member must be incremented by one. The year is measured from 1900. Therefore, in Line 14, the tm_year
member must be adjusted.
Copyright © 1997-2024 by QPBC.
All rights reserved