c语言中写入日期和时间。
1、
#include <stdio.h> #include <time.h> int main(void) { FILE *fp; time_t current = time(NULL); struct tm *timer = localtime(¤t); if((fp = fopen("xxx.txt","w")) == NULL) printf("\afile does not exist.\n"); else { fprintf(fp, "%d - %d - %d - %d - %d - %d\n", timer -> tm_year + 1900,timer -> tm_mon + 1 ,timer -> tm_mday, timer -> tm_hour,timer -> tm_min,timer ->tm_sec); printf("written successfully.\n"); } return 0; }