取得当前时间函数
void GetCurrentTime(char *BeginDate,char *EndDate)
{
char currTime[20];
char BeginTime[20];
char EndTime[20]="";
char month[4]="";
char day[4]="";
char tempm[4]="";
struct tm *p;
time_t t;
int Id=0;
time(&t);
p = localtime(&t);
printf("\n进入GetCurrentTime函数中..");
sprintf(currTime,"%d",1900+p->tm_year);
(void)strcat(currTime,"-");
if((1+p->tm_mon)>12)
{
(void)strcpy(month,"01");
(void)strcat(currTime,month);
}
else if((1+p->tm_mon)<10)
{
(void)strcat(tempm,"0");
sprintf(month,"%d",1+p->tm_mon);
(void)strcat(tempm,month);
(void)strcat(currTime,tempm);
}
else
{
sprintf(month,"%d",1+p->tm_mon);
(void)strcat(currTime,month);
}
/*开始时间*/
(void)strcat(BeginTime,currTime);
(void)strcat(BeginTime,"-01");
(void)strcat(BeginTime," 00:00:00");
sprintf(day,"%d",p->tm_mday);
/*结束时间*/
(void)strcat(EndTime,currTime);
(void)strcat(EndTime,"-");
(void)strcat(EndTime,day);
(void)strcat(EndTime," 23:59:59");
(void)strcpy(BeginDate,BeginTime);
(void)strcpy(EndDate,EndTime);
}
{
char currTime[20];
char BeginTime[20];
char EndTime[20]="";
char month[4]="";
char day[4]="";
char tempm[4]="";
struct tm *p;
time_t t;
int Id=0;
time(&t);
p = localtime(&t);
printf("\n进入GetCurrentTime函数中..");
sprintf(currTime,"%d",1900+p->tm_year);
(void)strcat(currTime,"-");
if((1+p->tm_mon)>12)
{
(void)strcpy(month,"01");
(void)strcat(currTime,month);
}
else if((1+p->tm_mon)<10)
{
(void)strcat(tempm,"0");
sprintf(month,"%d",1+p->tm_mon);
(void)strcat(tempm,month);
(void)strcat(currTime,tempm);
}
else
{
sprintf(month,"%d",1+p->tm_mon);
(void)strcat(currTime,month);
}
/*开始时间*/
(void)strcat(BeginTime,currTime);
(void)strcat(BeginTime,"-01");
(void)strcat(BeginTime," 00:00:00");
sprintf(day,"%d",p->tm_mday);
/*结束时间*/
(void)strcat(EndTime,currTime);
(void)strcat(EndTime,"-");
(void)strcat(EndTime,day);
(void)strcat(EndTime," 23:59:59");
(void)strcpy(BeginDate,BeginTime);
(void)strcpy(EndDate,EndTime);
}
浙公网安备 33010602011771号