CTime使用总结

上传人:xy****7 文档编号:45537915 上传时间:2018-06-17 格式:DOC 页数:6 大小:36KB
返回 下载 相关 举报
CTime使用总结_第1页
第1页 / 共6页
CTime使用总结_第2页
第2页 / 共6页
CTime使用总结_第3页
第3页 / 共6页
CTime使用总结_第4页
第4页 / 共6页
CTime使用总结_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《CTime使用总结》由会员分享,可在线阅读,更多相关《CTime使用总结(6页珍藏版)》请在金锄头文库上搜索。

1、CTimeCTime 使用总结使用总结CTime( ) throw( );CTime(_time64_t time ) throw( );CTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec,int nDST = -1 );CTime(WORD wDosDate,WORD wDosTime,int nDST = -1 );CTime(const SYSTEMTIMECTime(const FILETIMECTime(const DBTIMESTAMPnDST Indicates whether daylight savi

2、ngs time is in effect. Can have one of three values: nDST set to 0 Standard time is in effect. nDST set to a value greater than 0 Daylight savings time is in effect. nDST set to a value less than 0 The default. Automatically computes whether standard time or daylight savings time is in effect.初始化 m_

3、begintime=CTime(2004,1,1,0,0,0,-1);/参数依次为year,month,day,hour,minite,second,nDSTm_endtime =CTime:GetCurrentTime();/当前时间2.日期比较CTimeSpan span;span=time1-time2;得到两时间的间隔.可以取得 span.GetHours().等3.access 数据库查询使用 DateDiff()函数,具体参照 access 帮助CString timesql;timesql.Format(“ Where DateDiff(d,%s,%s)year,(var.m_p

4、date)-month,(var.m_pdate)-day);5.CTime 转换为 CString例:m_begintime.Format(“%Y-%m-%d“);/2004-10-036.CString 转换为 CTime/s=“2004-10-5“int first=s.Find(-);int second=s.Find(-,first+1);int year=atoi(s.Left(4);int month=atoi(s.Mid(first+1,second-first+1);int day=atoi(s.Mid(second+1,s.GetLength()-second-1);CTi

5、me temp(year,month,day,0,0,0);7.判断 CString 是否表示的正确日期格式/判断是否为 2004-01-13 ch 可代表其他分隔符bool IsDate(CString str,char ch)if(str.IsEmpty() return false;/日期分段int first=str.Find(ch);int second=str.Find(ch,first+1);int year=atoi(str.Left(4);int month=atoi(str.Mid(first+1,second-first+1);int day=atoi(str.Mid(s

6、econd+1,str.GetLength()-second-1);/判断if (year = 2010)return false;else if (month12)return false;else if (day 31)return false;else if (month = 4 | month = 6 | month = 9 | month = 11)if(day 30)return false;elsereturn true;else if (month = 2)if (year % 4 = 0 elsereturn true;else if (day28)return false;

7、return true;elsereturn true;用 VC 编写数据库程序不可避免的会遇到_bstr_t 、CString 、CTime 这几个类型之间的转换问题,令人头疼。今早上终于算是解决了 CString 和 CTime 的类型转换问题。/CTime-CStringCTime t;t=CTime:GetCurrentTime();CString sur;sur.Format(“%s“,t.Format(“%Y-%m-%d“);MessageBox(sur);/long CStringlong a ;CString b;b.format(“%ld“,a);/double -CStri

8、ngdouble a;CString b;b.format(“%f“,a);/CString-CTimeCString sur;sur=“2006-08-09“;COleDateTime time1;time1.ParseDateTime(sur);SYSTEMTIME systime;VariantTimeToSystemTime(time1, CTime tm(systime);m_time=tm;UpdateData(false);CString 和 int,float 之间的转换。1。int CString1) int -CStringint n = 1;CString str;str

9、.Format(“%d“,n);2) CString-intCString str = “1“;int n = atoi(str.GetBuffer(0);2. char* 与 CString1)char*-CStringchar sz128;CString str;str.Format(“%s“,sz);2) CString - char*CString str;int nLength = str.GetLength();char* sz = new charnLength;sz = str.GetBuffer(0);3. floatCString1)float-CStringfloat f

10、 = 0.0;CString str;str.Format(“%f“,f);2) CString-floatCString str = “0.0“;float f = atof(str.GetBuffer(0);Format 函数第一个参数是要转的那个数的类型FileTime 和 CTime 之间的转换问题1. FileTime 转换成 CTime 方法(1) FILETIME ft; CTime time(ft); 方法(2) FILETIME ft; SYSTEMTIME st; BOOL bSuccess=:FileTimeToSystemTime( 2. CTime 转换成 FileTime CTime time(CTime:GetCurrentTime(); SYSTEMTIME st; time.GetAsSystemTime(st); FILETIME ft; :SystemTimeToFileTime(

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号