下面给出一个sscanf用法,格式化拿取数据的方式。
int iLen = strlen("YYYY-MM-DD HH:mm:ss");
if (strTime.length() >= iLen)
{
int iYear = 0;
int iMonth = 0;
int iDay = 0;
int iHour = 0;
int iMinute = 0;
int iSecond = 0;
int iCount = sscanf(strTime.c_str(), "%04d-%02d-%02d %02d:%02d:%02d", \
&iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond);
if (iCount == 6)
{
//TODO
}
}