?C/C++???,?????????????:
- time??:time?????1970?1?1???????????????time(NULL)????????
#include#include int main() { time_t currentTime; time(¤tTime); printf("Current time: %s", ctime(¤tTime)); return 0; }
- clock??:clock???????????????????CLOCKS_PER_SEC?????????????
#include#include int main() { clock_t start = clock(); // ??????????? clock_t end = clock(); double timeUsed = (double)(end - start) / CLOCKS_PER_SEC; printf("Time used: %lf seconds", timeUsed); return 0; }
- gettimeofday??:gettimeofday????????????????
#include#include int main() { struct timeval currentTime; gettimeofday(¤tTime, NULL); printf("Current time: %ld seconds, %ld microseconds", currentTime.tv_sec, currentTime.tv_usec); return 0; }
- localtime??:localtime????????????????
#include#include int main() { time_t currentTime; time(¤tTime); struct tm* localTime = localtime(¤tTime); printf("Current time: d-d-d d:d:d", localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); return 0; }
???C/C++???????????????,????????????????