Visual C++:CString,char*,int,COleDateTime,CTime,time_t之间的相互转换
来源:互联网 发布:淘宝客微信群机器人 编辑:程序博客网 时间:2024/06/06 06:55
获取当前时间。
datetime = COleDateTime::GetCurrentTime();
CTime和COleDateTime具有几乎同样的功能。
与CTime相比, COleDateTime的优点在于它支持DWORD变量。
COleDateTime使用的位数是双浮点的两倍,既然CTime只是简单地计算从1970年1月1日之后经过的秒数,所以到了2 0 3 7年它将达到4 2 9 4 9 6 7 2 9 5,从而不能再使用。
//CString--->COleDateTime
COleVariant vtime(strCString);COleDateTime time4=vtime;
//CTime--->time_t
COleDateTime time3(time2);
//time_t--->COleDateTime.
CString COleDateTime CTime互相转换
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time1, &systime);
CTime tm(systime);
time_t time2=tm.GetTime(); //CTime--->time_t
COleDateTime time3(time2); //time_t--->COleDateTime
CString str = tDate.Format(_T("%Y-%m-%d"));
=========================================================
include
using namespace std;
#include
{
CString strCString="ABC";
char strchar[256],*pstr;
pstr=(LPSTR)(LPCTSTR)strCString; //CString---->char*
strcpy(strchar,(LPSTR)(LPCTSTR)strCString); //CString---->char[]
_bstr_t strbstr=pstr; //char*---->_bstr_t
WCHAR *strWCHAR=strbstr; //b_str_t--->UNICODE
strbstr=strWCHAR;
pstr=strbstr; //UNICODE---->char*
strCString="10";
int istr=atoi((LPSTR)(LPCTSTR)strCString); //CString、char[]、char*------>int
strCString.Format("%d",istr); //int----->CString
sprintf(strchar,"%d",istr); //int----->char[]
pstr=new char[256]; //字符串申请空间
strcpy(pstr,"ABC"); //字符串赋值
delete []pstr; //字符串释放
string strstring="ABC";
pstr=(char*)strstring.c_str(); //string---->char*
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time1, &systime);
CTime tm(systime);
time_t time2=tm.GetTime(); //CTime--->time_t
COleDateTime time3(time2); //time_t--->COleDateTime
//判断字符串是否是某种类型
CString sValue("123.1");
COleVariant vValue(sValue);
BOOL bStrIsFloat = (SUCCEEDED(VariantChangeType(&vValue, &vValue, 0, VT_R8)) && sValue.Find('.') != -1);
if(bStrIsFloat)
{
AfxMessageBox("浮点");
}
}
datetime = COleDateTime::GetCurrentTime();
CTime和COleDateTime具有几乎同样的功能。
与CTime相比, COleDateTime的优点在于它支持DWORD变量。
COleDateTime使用的位数是双浮点的两倍,既然CTime只是简单地计算从1970年1月1日之后经过的秒数,所以到了2 0 3 7年它将达到4 2 9 4 9 6 7 2 9 5,从而不能再使用。
//CString--->COleDateTime
COleVariant vtime(strCString);COleDateTime time4=vtime;
//CTime--->time_t
COleDateTime time3(time2);
//time_t--->COleDateTime.
CString COleDateTime CTime互相转换
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time1, &systime);
CTime tm(systime);
time_t time2=tm.GetTime(); //CTime--->time_t
COleDateTime time3(time2); //time_t--->COleDateTime
CString str = tDate.Format(_T("%Y-%m-%d"));
=========================================================
include
using namespace std;
#include
{
CString strCString="ABC";
char strchar[256],*pstr;
pstr=(LPSTR)(LPCTSTR)strCString; //CString---->char*
strcpy(strchar,(LPSTR)(LPCTSTR)strCString); //CString---->char[]
_bstr_t strbstr=pstr; //char*---->_bstr_t
WCHAR *strWCHAR=strbstr; //b_str_t--->UNICODE
strbstr=strWCHAR;
pstr=strbstr; //UNICODE---->char*
strCString="10";
int istr=atoi((LPSTR)(LPCTSTR)strCString); //CString、char[]、char*------>int
strCString.Format("%d",istr); //int----->CString
sprintf(strchar,"%d",istr); //int----->char[]
pstr=new char[256]; //字符串申请空间
strcpy(pstr,"ABC"); //字符串赋值
delete []pstr; //字符串释放
string strstring="ABC";
pstr=(char*)strstring.c_str(); //string---->char*
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time1, &systime);
CTime tm(systime);
time_t time2=tm.GetTime(); //CTime--->time_t
COleDateTime time3(time2); //time_t--->COleDateTime
//判断字符串是否是某种类型
CString sValue("123.1");
COleVariant vValue(sValue);
BOOL bStrIsFloat = (SUCCEEDED(VariantChangeType(&vValue, &vValue, 0, VT_R8)) && sValue.Find('.') != -1);
if(bStrIsFloat)
{
AfxMessageBox("浮点");
}
}
- Visual C++:CString,char*,int,COleDateTime,CTime,time_t之间的相互转换
- CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数
- CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数
- CString COleDateTime CTime之间的转换
- CString、char、string、int、_bstr_t、CTime、COleDateTime相互转换&判断一个字符串是一个浮点数
- [转]CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数
- [转]CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数
- [转]CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数
- CString时间字符串,COleDateTime,CTime类之间的转换
- CString 时间字符串、COleDateTime 和 CTime 类之间的转换
- CString 时间字符串、COleDateTime 和 CTime 类之间的转换
- CString 时间字符串、COleDateTime 和 CTime 类之间的转换
- CString时间字符串,COleDateTime,CTime类之间的转换
- CString时间字符串,COleDateTime,CTime类之间的转换
- VC++ 时间类型转换: CTime, COleDateTime, time_t, CString
- VC++ 时间类型转换: CTime, COleDateTime, time_t, CString .
- MFC CString Char* int之间相互转换。
- 总结:string,char*,CString,int,WCHAR*之间的相互转换:
- 关于测试文档
- diff/patch 的使用
- TreeSet 使用指定比较器进行排序
- erlang使用rebar generate生成发行包时,去除subversion的目录
- 配置android虚拟机的中文路径问题: PANIC: Could not open:
- Visual C++:CString,char*,int,COleDateTime,CTime,time_t之间的相互转换
- Why won't my UIViewController rotate with the device?
- 调试中的困难
- 回发或回调参数无效。ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- Building a Small Embedded Linux Kernel Example
- 智能指针和弱引用
- 关于fan客•尚汇项目开发的个人总结
- 苹果App Store程序提交审核指南中文版
- Map Reduce – the Free Lunch is not over?