stringToTime && timeToString,
分享于 点击 2926 次 点评:104
stringToTime && timeToString,
void timeToString(const time_t& time, std::string& str){
tm tm1;
localtime_s(&tm1, &time);
char c_time[15];
sprintf_s(c_time, "%2d-%1d-%2d", tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday);
std::string str_(c_time);
str = str_;
}
int stringToTime(time_t &timeData, const std::string &strDateStr)
{
char *pBeginPos = (char*)strDateStr.c_str();
char *pPos = strstr(pBeginPos, "-");
if (pPos == NULL)
{
return -1;
}
int iYear = atoi(pBeginPos);
int iMonth = atoi(pPos + 1);
pPos = strstr(pPos + 1, "-");
if (pPos == NULL)
{
return -1;
}
int iDay = atoi(pPos + 1);
struct tm sourcedate;
memset((void*)&sourcedate, 0, sizeof(sourcedate));
sourcedate.tm_mday = iDay;
sourcedate.tm_mon = iMonth - 1;
sourcedate.tm_year = iYear - 1900;
timeData = mktime(&sourcedate);
return 0;
}
相关文章
- 暂无相关文章
用户点评