formatieren von Zeitangaben
-
Hallo Leute, ich benutze die funktion GetLocalTime der WinApi um fie lokale Zeit zu ermitteln. Nun möchte ich mit der erhaltenen SYSTEMTIME struktur rechnen bzw. diese formatieren, habe dafür jedoch keine funktionen gefunden. Könnt ihr mir helfen ?? Gruss Ishildur
-
Bei den Remarks steht doch, wie du damit rechnen sollst:
Convert the SYSTEMTIME structure to a FILETIME structure.
Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
Use normal 64-bit arithmetic on the ULARGE_INTEGER value.Zum ausgeben kannst du dir ja einfach die einzelnen Parameter der SYSTEMTIME-Struktur mit wsprintf in einen String (char Array) schreiben
-
Also, ich Blick nicht so richtig durch!
Kannst du mir mal eine Beispielfunktion schreiben, sagen wir "addDays(SYSTEMTIME &st, int cDay)"; Die funkton soll die übergebene SYSTEMTIME - struktur um die im zweiten Parameter definierte Zahl von Tagen erhöhen.
Vielen Dank, Ishildur
-
#include <stdio.h> #include <windows.h> void addDays (SYSTEMTIME*, int) ; int main (void){ SYSTEMTIME st ; memset (&st, 0, sizeof(SYSTEMTIME)) ; GetSystemTime (&st) ; addDays (&st, 10) ; printf ("%d", st.wDay) ; return 0 ; } void addDays (SYSTEMTIME *st, int iDay) { st->wDay += iDay ; }
ich glaube so musste es funzen (macht aber nicht viel sinn...)
-
Ach komm schon, das ist doch nicht dein Erst oder?
Was ist wenn das aktuelle Datum der 31. Januar 2002 ist?
Wenn du dann einen Tag dazuzählst, musst du den wDay auf 1 setzen und den wMonth um eins inkrementieren. Das währe an sich auch kein Problem, wenn da nicht noch die Schaltjahre währen!Gruss Ishildur
-
Convert the SYSTEMTIME structure to a FILETIME structure.
Aber die beiden Datenstrukturen haben ja gar nicht die gleiche Grösse?! SYSTEMTIME ist nämlich doppelt so gross wie FILETIME!
sizeof(SYSTEMTIME) = 16Byte (128Bit)
sizeof(FILETIME) = 8Byte (64Bit)
-
Du sollst auch nicht einfach hin und her casten, du sollst konvertieren. Schau Dir doch in der Hilfe mal die Time Functions an. Dann springt Dich die Funktion SystemTimeToFileTime doch förmlich an.
[edit]
Eine Möglichkeit zum Addieren:SYSTEMTIME* AddDays(SYSTEMTIME* pst, UINT_PTR uDays) { LARGE_INTEGER li; FILETIME ft; li.QuadPart = 24 * 60 * 60; li.QuadPart *= 10000000; li.QuadPart *= uDays; SystemTimeToFileTime(pst, &ft); ((LARGE_INTEGER*)&ft)->QuadPart += li.QuadPart; FileTimeToSystemTime(&ft, pst); return(pst); }
Ach, und formatieren wolltest Du auch noch: GetDateFormat, GetTimeFormat
[/edit]
-
-King- schrieb:
li.QuadPart = 24 * 60 * 60;
li.QuadPart *= 10000000;
li.QuadPart *= uDays;wieso muss man die erste Zeile "li.QuadPart = 24 * 60 * 60" noch "* 10000000" nehmen?
Logisch wäre aber "* 100 (Milisekunden)"thx
-
MSDN schrieb:
A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 (UTC).
[msdn]File Times[/msdn]
-
alles klar.
thx
-
toom schrieb:
Logisch wäre aber "* 100 (Milisekunden)"
Nö, logisch wären (wenn überhaupt) * 1000.