CTime 的使用


源文出處:http://blog.163.com/li_hai_quan/blog/static/3953973920081150315696/


CTime

CTime==>CString

CTime time;

time.GetCurrentTime();

CString str;

str.Format("%s",time.Format("%y:%m:%d %H-%M-%S")

1

CString str;

CTime t = CTime::GetCurrentTime();

str.Format("%d-%d-%d",t.GetYear(),t.GetMonth(),t.GetDay());

2

CString strTime;

CTime tTime = CTime::GetCurrentTime();

strTime = tTime.Format("%Y-%m-%d %H:%M:%S");

CString ==>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

時間差

COleDateTime strFirst,strEnd;

strFirst = COleDateTime(strFirst.GetYear(),strFirst.GetMonth(),strFirst.GetDay(),0,0,0);

strEnd = COleDateTime(tmCurrent.GetYear(),tmCurrent.GetMonth(),tmCurrent.GetDay(),23,59,59);

tspan= strEnd - strFirst;

注:兩個時間相減時,小時數不足24小時的,自動略去,不做一天計算。如7.1號 5點與7.2號3點間,就不能計算爲一天。想要得出結果爲一天的,要注意小時的賦值!!



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章