I am using Win 98 with Microsof Visual C++ 6.0. How can I get the number of seconds since midnight?
Printable View
I am using Win 98 with Microsof Visual C++ 6.0. How can I get the number of seconds since midnight?
GetTickCount counts the milliseconds since you computer's been on....turn it on a midnight :p just kidding! :D
the Time API will give you the time....I've never really used it so I can't tell you what math you'd need after that but you should be able to figure it out....I'll do one now....it seems interresting! (a huge number too considering its 11:36 pm now!)
:D
Well it is not a huge number as you say because in 24 hrs there are 86400 seconds, and that can easily be put into an integer.
Hey i'm new to C++. BTW, this is a console program. How do I do it?
Even though you're using console, you can still use the Win32 API (as long as its a Win32 Console, and not a DOS program).
Just include windows.h> and use whatever you want
Well I'm saying it would be huge compared the the total...since there were only a few minutes left in the day...btw how do you use time.h? This thread got me interrested in doing this but I keep getting the same # :(
It would have to be in a long, rather than an int, because the int (unsigned) can only store up to 65535.Quote:
Originally posted by Vlatko
Well it is not a huge number as you say because in 24 hrs there are 86400 seconds, and that can easily be put into an integer.
Here's code that works....
PHP Code:#include <windows.h>
#include <stdio.h>
void main(void){
long elapsed =0;
// Create system time structure
SYSTEMTIME *SystemTime, Sys;
SystemTime = &Sys;
GetLocalTime(SystemTime);
elapsed = SystemTime->wSecond;
elapsed += (SystemTime->wMinute * 60);
elapsed += (SystemTime->wHour * 3600);
printf("Secs since midnight %d\n",elapsed);
}
Megatron integers are 4 butes long in C++ so an integer can hold values from –2,147,483,648 to 2,147,483,647. Long is also an integer (long integer) but it has the same range as an integer.
Unsigned short int can hold values up to 65535 not just an integer.