Fehlerhafte Berechnung von Zeitdifferenz mit SYSTEMTIME
-
Hallo Leute, könnt ihr mir sagen, wieso mir die untenstehende Methode immer eine Sekunde zuviel berechnet? Bsp. Seit der instanzierung des Objekts bis zum jetzigen Zeitpunkt sind genau 156 millisekunden vergangen. Die Methode kommt aber zum Ergebnis: 1 Sekunde + 156 Millisekunden. Hat jemand von euch eine Idee, wieso??
// -------------------- method for getting the life - time of this instance ------------------- const KRV_Time *KRV_Object::getLifeTime(void) const{ // declare local variables SYSTEMTIME tmCrt,tmCurr,tmDiff; FILETIME ftmCrt,ftmCurr,ftmDiff; LARGE_INTEGER liCrt,liCurr,liDiff; // get the creation- and the current time tmCrt = this->tmCrt; GetLocalTime(&tmCurr); // covert both SYSTEMTIME - structs into FILETIME - structs SystemTimeToFileTime(&tmCrt,&ftmCrt); SystemTimeToFileTime(&tmCurr,&ftmCurr); // copy both filetime - structs into LARGER_INTEGER - structs CopyMemory(&liCurr,&ftmCurr,sizeof(FILETIME)); CopyMemory(&liCrt,&ftmCrt,sizeof(FILETIME)); // subtract the creationtime from the currentime liDiff.QuadPart = liCurr.QuadPart - liCrt.QuadPart; // inverse all operations with the result CopyMemory(&ftmDiff,&liDiff,sizeof(LARGE_INTEGER)); FileTimeToSystemTime(&ftmDiff,&tmDiff); // return a pointer to the SYSTEMTIME struct holding the calculated life - time return &(this->tmLife = tmDiff); } // --------------------------------------------------------------------------------------------
-
Beantwortet zwar nicht deine Frage, aber wäre es nicht einfacher / besser gleich GetTickCount zu verwenden, wenn du nur an einer Zeitdifferenz interessiert bist?!
-
Die Klasse KRV_Object enthält aber auch eine Methode "const KRV_Time *getCreationTime(void) const;