C語言:獲取當前時間,並轉為字符串,這個功能挺常用的,記錄一下:
#include <time.h>
#include <stdio.h>
int main()
{
time_t nowtime = time(NULL);
tm *now = localtime(&nowtime);
printf("now: %04d-%02d-%02d %02d:%02d:%02d\nunix time: %ld\n",
now->tm_year+1900, now->tm_mon+1, now->tm_mday,
now->tm_hour, now->tm_min, now->tm_sec, (long)nowtime);
return 0;
}