当前位置: 技术问答>linux和unix
如何用日期来给文件取名?
来源: 互联网 发布时间:2015-04-20
本文导语: 我需要用日期来给文件取名,进行数据库的备份工作, 怎么给rq赋值? rq= filename=rq.dmp 如:20031011.dmp | 如下代码: ..... static char filename[32] time_t curtime = time(NULL); sprintf(filename,"%s", "dmp") strftime((f...
我需要用日期来给文件取名,进行数据库的备份工作,
怎么给rq赋值?
rq=
filename=rq.dmp 如:20031011.dmp
怎么给rq赋值?
rq=
filename=rq.dmp 如:20031011.dmp
|
如下代码:
.....
static char filename[32]
time_t curtime = time(NULL);
sprintf(filename,"%s", "dmp")
strftime((filename+strlen(filename)),10,".%y%m%d",localtime(&curtime));
if ((fp = fopen(filename,"aw")) == NULL) {
fprintf(stderr,"Can't open log file:[%s]n",filename);
return;
}
....
.....
static char filename[32]
time_t curtime = time(NULL);
sprintf(filename,"%s", "dmp")
strftime((filename+strlen(filename)),10,".%y%m%d",localtime(&curtime));
if ((fp = fopen(filename,"aw")) == NULL) {
fprintf(stderr,"Can't open log file:[%s]n",filename);
return;
}
....