c语言以时间作为文件名|c语言文件读写怎么让生成的txt文件名是系统时间

c语言以时间作为文件名|c语言文件读写怎么让生成的txt文件名是系统时间的第1张示图

㈠ 数字型转字符串!C语言里如何以系统日期为TXT文件名保存数据

用sprintf()函数,示例:#include <stdio.h>#include <time.h>void main(){ struct tm *newtime;char filename[20]; /*用于保存最后生成的字符串*/time_t long_time;time(&long_time);newtime=localtime(&long_time);sprintf(filename,"%d-%d-%d",newtime->tm_year+1900,newtime->tm_mon+1,newtime->tm_mday);/*将newtime的各个成员将字符串的方式输出到filename字符数组中*/printf("%s\n",filename);/*输出字符串*/}

㈡ C# 创建一个文件,以当前系统时间为文件名

string fileName = String.Format(@"d:\{0}.txt", DateTime.Now.ToString("yyyyMMHH")); //文件名作为日期 if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName); System.IO.TextWriter writer = System.IO.File.CreateText(fileName); // 创建TextWriter对象 writer.WriteLine(“您的内容”); writer.Flush(); // 缓存写入。 writer.Close();

㈢ c语言如何用系统时间给文件命名精确到毫秒级

GetCurrentTime();//不过达不到你要求的毫秒级

㈣ C 获得系统时间并把该时间作为保存数据的.txt文件名 详细C语言程序

#include <stdio.h>#include <time.h>void main(void){struct tm *newtime;FILE *f;time_t ltime;time (&ltime); /* Get the time in seconds */newtime = localtime(&ltime); /* convert it to the structure tm */f=fopen(“TIME.TXT”."w");fprintf(f,"The current time and date are %s", asctime(newtime));/* print the local time as a string */fclose(f);}

㈤ 求C++保存文件以系统时间命名的方法

在StartSave之前要确定保存的文件名,文件名中要包含时间:

CTimecurrTime;currTime=CTime::GetCurrentTime();CStringstrTime;strTime.Format(_T("%.4d-%.2d-%.2d-%.2d-%.2d-%.2d"),currTime.GetYear(),currTime.GetMonth(),currTime.GetDay(),currTime.GetHour(),currTime.GetMinute(),currTime.GetSecond());

以上的代码中,strTime中会记录当前的时间格式为“年年年年-月月-日日-时时-分分-秒秒”

需要把这段字符添加到文件名中去:

CStringstrPath;strPath=_T("d:\nbumooc\raw_")+strTime+_T(".ts");StartSave("10.1.58.84",strPath);

简单来说,用上面的两段代码替换一下StartSave();

㈥ 用C语言把当前时间作为txt文本的名称

调用getdate和gettime函数时应在程序前面包含命令行: #include<dos.h> 说明: (1)在dos.h中已说明struct date结构如下: struct date { int da_year;/*现年*/ char da_day;/*月的日*/ char da_mon;/*月(1=jan)*/ }; (2)在dos.h中说明struct time结构如下: struct time { unsigned char ti_min;/*分*/ unsigned char ti_hour;/*时*/ unsigned char ti_hund;/*百分之一秒*/ unsigned char ti_sec;/*秒*/ }; /*下面是把系统当前日期、时间填入所指结构中的两个函数原型*/ void getdate(struct date*pdate); void gettime(struct time*ptime); 以上由hanxuaiztt提供 http://..com/question/8258745.html?fr=qrl

㈦ 怎样用C语言创建一个文本文件,文件名中包含字符和当前系统时间并且文件名随系统时间改变

#include <string.h>把系统时间获取之后用strcat(str1,str2);字符串串联命令,这个命令将数组str2储存的字符串连接到str1后面。然后再用fopen(str1,"w");就可以创建了。

㈧ 用C语言每隔三秒建立一个以日期时间命名的文件

具体抄实现袭的步骤如下:

time_tnow;structtm*curTime;charfilename[256];while(1){now=time(NULL);curTime=localtime(&now);sprintf(filename,"%04d-%02d-%02d%02d-%02d-%02d",curTime->tm_year+1900,curTime->tm_mon+1,curTime->tm_mday,curTime->tm_hour,curTime->tm_min,curTime->tm_sec);fp=fopen(filename,"w");fclose(fp);sleep(3);}

㈨ c# 如何用当前时间作为文件名

System.DateTime myTime=new System.DateTime(); 这样就可以获得系统的时间, myTime=DateTime.Now();a=myTime;

㈩ c语言文件读写怎么让生成的txt文件名是系统时间

struct tm *newtime; char tmpbuf[128]; time_t lt1; lt1 = time(NULL); newtime=localtime(&lt1); strftime( tmpbuf, 128, "data_%Y%m%d_%H%M%S.txt", newtime);FILE *fp = fopen(tmpbuf, "wt");

未经允许不得转载:山九号 » c语言以时间作为文件名|c语言文件读写怎么让生成的txt文件名是系统时间

赞 (0)