给你一个函数:
#include <stdio.h>
#include <string.h>
#include <time.h>
void GETDATE(char *date_buff)
{
struct tm *tm_p;
char buff[9];
static time_t clk_seed;
clk_seed = time((long *)0);
tm_p = localtime(&clk_seed);
if(tm_p->tm_year!=0)
tm_p->tm_year=1900+tm_p->tm_year;
else
tm_p->tm_year=2000+tm_p->tm_year;
sprintf(buff, "%.4d%.2d%.2d",
/*tm_p->tm_year%100, tm_p->tm_mon + 1, tm_p->tm_mday);*/
tm_p->tm_year, tm_p->tm_mon + 1, tm_p->tm_mday);
buff[8]='/0';
strncpy(date_buff,buff,8);
}
void main()
{
char sZFile[100],datestr[9];
memset(sZFile,0,100);
memset(datestr,0,9);
GETDATE(datestr);
sprintf(sZFile,"c://%s.txt",datestr);
printf("szfile=%s/n",sZFile);
}