1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <stdio.h> #include <time.h>int getnowtime (char *nowtime) {char acyear[5] = {0};char Acmonth[5] = {0}; Char acday[5] = {0};char Achour[5] = {0};char Acmin[5] = {0};char Acsec[5] = {0};time_t now; struct tm* timenow; Time (&now); TimeNow = LocalTime (&now); Strftime (Acyear,sizeof (acyear), "%Y", TimeNow); Strftime (Acmonth,sizeof (Acmonth), "%m", TimeNow); Strftime (Acday,sizeof (Acday), "%d", timenow); Strftime (Achour,sizeof (Achour), "%H", TimeNow); Strftime (Acmin,sizeof (acmin), "%M", TimeNow); Strftime (Acsec,sizeof (acsec), "%s", TimeNow); Strncat (Nowtime, Acyear, 4); Strncat (Nowtime, Acmonth, 2); Strncat ( Nowtime, Acday, 2); Strncat (Nowtime, Achour, 2); Strncat (Nowtime, Acmin, 2); Strncat (Nowtime, acsec, 2); return 0;} int main (int argc, char *argv[]) {char nowtime[32] = {0}; Getnowtime (Nowtime); printf ("Nowtime is%s.\n", nowtime); return 0;} |