c语言 time() 秒数转换为指定格式的时间字符串
作者:互联网
static int secondToDate(time_t sec, char *pDate, char *pTime)
{
char ctemp[20] ={0};
struct tm *info;
int iLen = 0;
if(sec <= 0 || pTime == NULL) //|| pDate == NULL
{
printf("[%s]: para error\n", __func__);
return -1;
}
info=localtime(&sec);
strftime(ctemp, sizeof(ctemp), "%Y-%m-%d %H:%M:%S", info);
iLen = strstr(ctemp, " ") - ctemp;
memcpy(pDate, ctemp, iLen);
memcpy(pTime, &ctemp[iLen+1], strlen(&ctemp[iLen+1]));
return 0;
}
标签:info,__,ctemp,iLen,char,sec,time,字符串,秒数 来源: https://blog.csdn.net/u010068160/article/details/119141600