Uma maneira:
1 #include <windows.h> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstdio> 5 #include <time.h> 6 usando espaço de nomes STD; 7 8 int principal ( int argc, carvão animal ** argv) 9 { 10 cout << tempo (NULL) << endl; 11 time_t tmpcal_ptr; 12 struct tm * tmp_ptr = NULL; 13 14 tempo (& tmpcal_ptr); 15 // tmpcal_ptr = tempo (NULL); 两种取值方法均可以 16 printf ( " tmpcal_ptr =% d \ n " , tmpcal_ptr); 17 18 tmp_ptr = gmtime (& tmpcal_ptr); 19 printf ( " após gmtime, o tempo é: d%:% d:% d \ n " , tmp_ptr-> tm_hour, tmp_ptr-> tm_min, tmp_ptr-> tm_sec); 20 21 tmp_ptr = LocalTime (& tmpcal_ptr); 22 printf ( " após LocalTime, o tempo é:..% D% d% d " , ( 1900 + tmp_ptr-> tm_year), ( 1 + tmp_ptr-> tm_mon), tmp_ptr-> tm_mday); 23 printf ( " % d: d%:" , Tmp_ptr-> tm_hour, tmp_ptr-> tm_min, tmp_ptr-> tm_sec); 24 25 return 0 ; 26 }
Segunda maneira de precisão :( milissegundos)
1 #include <windows.h> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstdio> 5 #include <time.h> 6 usando espaço de nomes STD; 7 8 int principal () 9 { 10 sys SYSTEMTIME; 11 GetLocalTime (& sys); 12 printf ( " % 4D /% 02d /%% 02d 02d:% 02d:.%% 02d 03d星期% 1d \ n " , sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, sys.wDayOfWeek); 13 }