c語言中寫入日期和時間


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;
} 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM