这个功能挺常用的,记录一下:
?123456789101112#include <time.h> #include <stdio.h> int main() { time_t nowtime = time(NULL); tm *now = localtime(&nowtime); printf("now: %04d-%02d-%02d %02d:%02d:%02dnunix time: %ldn", now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec, (long)nowtime); return 0; }