how to get the system time

Started by
6 comments, last by da_cobra 22 years, 6 months ago
I use the visual c++ and I have a structure : struct time {int hours ; int minutes ; int seconds ; } ; now how do I read the system time and put it into that structure I already found how to read the system time and put it into a string, but I need it in that srtucture, so I can acces the hours, minutes and seconds by themself thanx in advance
Advertisement
Why not use the SYSTEMTIME structure:

SYSTEMTIME st;
GetSystemTime (&st);
cout << st.wHour << '':'' << st.wMinute << '':'' << st.wSecond;
what header file do I have to include for this structure?
windows.h
thanx that worked
but how come the hours he prints is 2 hours behind on my sytem time?!?
The system time (returned by GetSystemTime()) is expressed in Coordinated Universal Time (UTC), use GetLocalTime() instead (works the same way).
quote:From MSDN:

GetSystemTime


This function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).


You need to find the offset of your timezone from UTC. As always, the full documentation can be found at MSDN.
How about getting the localtime() instead of getting system time and converting it according to local timezone?

This topic is closed to new replies.

Advertisement