如何把一个日期字符串转成_variant_t,日期类型
CStringszTime("2008-8-808:08:08");把这个szTime转换成_variant_t类型怎么做?...
CString szTime("2008-8-8 08:08:08");把这个szTime转换成 _variant_t类型怎么做?
展开
1个回答
展开全部
1.CString可以直接转_variant_t。
CString szTime("2008-8-8 08:08:08");
_variant_t mt = szTime;
2._variant_t转CString用如下函数:
CString VariantToCString(_variant_t var)
{
CString str; //转换以后的字符串
switch(var.vt)
{
case VT_BSTR: //var is BSTR type
str=var.bstrVal;
break;
case VT_I2: //var is short int type
str.Format("%d",(int)var.iVal);
break;
case VT_I4: //var is long int type
str.Format("%d",var.lVal);
break;
case VT_R4: //var is float type
str.Format(".6f",(double)var.fltVal);
break;
case VT_R8: //var is double type
str.Format(".6f",var.dblVal);
break;
case VT_CY: //var is CY type
str=COleCurrency(var).Format();
break;
case VT_DATE: //var is DATE type
str=COleDateTime(var).Format();
break;
case VT_BOOL: //var is VARIANT_BOOL
str= (var.boolVal==0) ?L"FALSE": L"TRUE";
break;
default:
str.Format("Unk type %d\n",var.vt);
TRACE("Unknown type %d\n",var.vt);
}
return str;
}
CString szTime("2008-8-8 08:08:08");
_variant_t mt = szTime;
2._variant_t转CString用如下函数:
CString VariantToCString(_variant_t var)
{
CString str; //转换以后的字符串
switch(var.vt)
{
case VT_BSTR: //var is BSTR type
str=var.bstrVal;
break;
case VT_I2: //var is short int type
str.Format("%d",(int)var.iVal);
break;
case VT_I4: //var is long int type
str.Format("%d",var.lVal);
break;
case VT_R4: //var is float type
str.Format(".6f",(double)var.fltVal);
break;
case VT_R8: //var is double type
str.Format(".6f",var.dblVal);
break;
case VT_CY: //var is CY type
str=COleCurrency(var).Format();
break;
case VT_DATE: //var is DATE type
str=COleDateTime(var).Format();
break;
case VT_BOOL: //var is VARIANT_BOOL
str= (var.boolVal==0) ?L"FALSE": L"TRUE";
break;
default:
str.Format("Unk type %d\n",var.vt);
TRACE("Unknown type %d\n",var.vt);
}
return str;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询