void CDefineBundleTimeDlg::OnEndTimeChanged() { COleDateTime startTime; startTime.ParseDateTime(m_btnStartTime.ToString()); COleDateTime endTime; endTime.ParseDateTime(m_btnEndTime.ToString()); if (endTime <= startTime) { m_btnEndTime.SetDate(startTime); endTime.ParseDateTime(m_btnEndTime.ToString()); } COleDateTimeSpan sp = endTime - startTime; INT nHours = (long)sp.GetTotalHours(); INT nMinutes = sp.GetMinutes(); CString strTmp; strTmp.Format(_T("%d"), nHours); m_edtHours.SetWindowText(strTmp); strTmp.Format(_T("%d"), nMinutes); m_edtMinutes.SetWindowText(strTmp); TRACE("OnEndTimeChanged\n"); }
CString CActiveMember::GetUseTimeAsString() { CString strTmp; if ( GetIsOnLine() ) { COleDateTime dtNow = COleDateTime::GetCurrentTime(); COleDateTimeSpan dts = dtNow - CheckInTime; //系统时间跟中心事件有差错时,可能存在为负的情况 if (dts < COleDateTimeSpan(0, 0, 0, 0))//时间为负 { strTmp.Format(_T("%.2d:%.2d"), 0, 0); } else//正常 { //{ 2011/04/22-gxx: 修改原来支持最大时长24小时为总时长, GetHours()-->GetTotalHours() int nHours = (int)dts.GetTotalHours(); strTmp.Format(_T("%.2d:%.2d"), nHours, dts.GetMinutes()); //} } } return strTmp; }
void TestDominoDocArtifact::TestModifiedTime() { COleDateTime currentTime = COleDateTime::GetCurrentTime(); DomDocHelper domDocHelper(TEST_ARTIFACT_FILE); DominoDocArtifact validArtifact(m_spLibrary, domDocHelper.DocumentId, domDocHelper.GetVersionLabel()); COleDateTime dominoDocmodifiedTime = validArtifact.ModifiedTime; assertTest(COleDateTime::invalid != dominoDocmodifiedTime.GetStatus()); assertTest(COleDateTime::null != dominoDocmodifiedTime.GetStatus()); COleDateTimeSpan OleDateTimeSpan = dominoDocmodifiedTime - currentTime; assertTest(0 == OleDateTimeSpan.GetHours()); assertTest(2 >= OleDateTimeSpan.GetMinutes()); }
CString CComputerInfo::GetUseTimeAsString() { CString strTmp; // 2011/07/11-8201-gxx: if (m_CheckInTime.GetStatus() == COleDateTime::invalid || m_CheckInTime.GetStatus() == COleDateTime::null) { return strTmp; } if (m_bHasUserInfo || ECS_UNLOCK == m_ComputerStatus) { COleDateTime dtNow = COleDateTime::GetCurrentTime(); COleDateTimeSpan dts = dtNow - m_CheckInTime; //系统时间跟中心事件有差错时,可能存在为负的情况 if (dts < COleDateTimeSpan(0, 0, 0, 0))//时间为负 { strTmp.Format(_T("%.2d:%.2d"), 0, 0); } else if( m_CheckInTime == 0 ) // 上机时间为0,表示没有上机 { strTmp = _T(""); return strTmp; } else//正常 { //{ 2011/04/22-gxx: 修改原来支持最大时长24小时为总时长, GetHours()-->GetTotalHours() int nHours = (int)dts.GetTotalHours(); strTmp.Format(_T("%.2d:%.2d"), nHours, dts.GetMinutes()); //} } } return strTmp; }
void CDlgBundleTimeList::OnOK() { INT nIndex = m_BundleTimeList.GetSelectionMark(); if (nIndex >= 0) { //取得绑定数据 INT nBtIndex = m_BundleTimeList.GetItemData(nIndex); m_nBundleTimeId = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeId(); m_nBundleTimeClassId = NetbarBundleTime.GetAt(nBtIndex).IsNowEnabled() ? 0 : 1; //开始时间 m_strStartTime = NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE).Left(5); //结束时间 m_strEndTime = NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE).Left(5); //包时扣费类型 m_nBundleTimeType = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeType(); COleDateTimeSpan RemainTime; if (NetbarBundleTime.GetAt(nBtIndex).GetStartTime().IsEmpty()) { RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0); } else { COleDateTime StartTime, EndTime, CurTime = COleDateTime::GetCurrentTime(); StartTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE)); StartTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(), StartTime.GetHour(), StartTime.GetMinute(), StartTime.GetSecond()); EndTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE)); EndTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(), EndTime.GetHour(), EndTime.GetMinute(), EndTime.GetSecond()); if (StartTime > EndTime) //跨天包时 { if (CurTime < EndTime) { StartTime -= COleDateTimeSpan(1, 0, 0, 0); //减去一天 } else { EndTime += COleDateTimeSpan(1, 0, 0, 0); //加上一天 } } if (CurTime < StartTime) //包时还没开始 { RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0); } else if (CurTime > EndTime) //包时已经过期,只能开始算明天的包时 { } else //包时正在进行 { RemainTime = EndTime - CurTime; } //AfxMessageBox(StartTime.Format(_T("%Y-%m-%d %H:%M:%S"))); //AfxMessageBox(EndTime.Format(_T("%Y-%m-%d %H:%M:%S"))); //AfxMessageBox(m_strRemainTime); } //m_strRemainTime = RemainTime.Format(_T("%H:%M:%S")); m_strRemainTime.Format(_T("%02d:%02d:%02d"), (long)RemainTime.GetTotalHours(), RemainTime.GetMinutes(), RemainTime.GetSeconds()); //包时金额 m_nBundleTimeMoney = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeMoney(); CBCGPDialog::OnOK(); } }
COleDateTimeSpan ts(3, 1, 5, 12); // 3 days, 1 hour, 5 min, and 12 sec ASSERT(ts.GetMinutes() == 5);
BOOL COptionsStats::OnInitDialog() { CPropertyPage::OnInitDialog(); CTime time(CGetSetOptions::GetTotalDate()); m_eAllDate = time.Format("%m/%d/%Y %I:%M %p"); m_eAllCopies.Format(_T("%d"), CGetSetOptions::GetTotalCopyCount()); m_eAllPastes.Format(_T("%d"), CGetSetOptions::GetTotalPasteCount()); CTime time2(CGetSetOptions::GetTripDate()); m_eTripDate = time2.Format("%m/%d/%Y %I:%M %p"); m_eTripCopies.Format(_T("%d"), CGetSetOptions::GetTripCopyCount()); m_eTripPastes.Format(_T("%d"), CGetSetOptions::GetTripPasteCount()); m_eClipsSent.Format(_T("%d"), theApp.m_lClipsSent); m_eClipsRecieved.Format(_T("%d"), theApp.m_lClipsRecieved); m_eLastStarted = theApp.m_oldtStartUp.Format(_T("%m/%d/%y %I:%M:%S")); if(theApp.m_oldtStartUp.GetHour() > 12) m_eLastStarted += " PM"; else m_eLastStarted += " AM"; COleDateTimeSpan span = COleDateTime::GetCurrentTime() - theApp.m_oldtStartUp; CString csSpan; csSpan.Format(_T(" - %d.%d.%d (D.H.M)"), (long)span.GetTotalDays(), span.GetHours(), span.GetMinutes()); m_eLastStarted += csSpan; try { m_eSavedCopies.Format(_T("%d"), theApp.m_db.execScalar(_T("SELECT COUNT(lID) FROM Main"))); m_eSavedCopyData.Format(_T("%d"), theApp.m_db.execScalar(_T("SELECT COUNT(lID) FROM Data"))); } CATCH_SQLITE_EXCEPTION __int64 size = FileSize(GetDBName()); const int MAX_FILE_SIZE_BUFFER = 255; TCHAR szFileSize[MAX_FILE_SIZE_BUFFER]; StrFormatByteSize(size, szFileSize, MAX_FILE_SIZE_BUFFER); m_eDatabaseSize = szFileSize; UpdateData(FALSE); theApp.m_Language.UpdateOptionStats(this); return TRUE; }