c语言中写入日期和时间。

1、

#include <stdio.h>
#include <time.h>

int main(void)
{
    FILE *fp;
    
    time_t current = time(NULL);
    struct tm *timer = localtime(&current);
    
    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;
} 

c语言中写入日期和时间_c语言

 

 c语言中写入日期和时间_it_02