VC 帮我截取2个字符

来源:百度知道 编辑:UC知道 时间:2024/04/28 10:25:46
xxx xxx 当前时间是 2009/8/13 上午 02:16
(上面的字符串是变动的)

我想截取02(时针)放入变量 int a;
截取16(分针)放入int b;
就是说我想截取:号的前2个数字 和:号后面的2个数字

。,帮我把代码出来吧~~~呵呵````谢谢啦

int idx = xxx.Find(":");

if(idx!=-1)
{
int a = atoi(xxx.Mid(idx-2,2));
int b = atoi(xxx.Mid(idx,2));
}

CTime tm;
tm = CTime::GetCurrentTime(); //取当前时间

CString strh,strm;
strh = tm.Format("%H"); //格式化小时
strm = tm.Format("%M"); //格式化分钟

int nh,nm;
nh = atoi(strh); //转换小时
nm = atoi(strm); //转换分钟