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;
}
c语言 time() 秒数转换为指定格式的时间字符串
最新推荐文章于 2022-05-20 14:06:43 发布