checking the current time in C++
-
-
hi there, Could anybody please help me in this: I need to check the current time in my application after each message that my application receives and whenever it is midnight I reset a counter inside my program. I appreciate any ideas Thanks, Nahitan
In your window's message procedure, do something like:
time_t t;
time(&t);
tm *now;
now = localtime(&t);
if (now->tm_hour ...)"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
In your window's message procedure, do something like:
time_t t;
time(&t);
tm *now;
now = localtime(&t);
if (now->tm_hour ...)"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,
-
Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,
So which of the three staments is in error? What does
%tm
do?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,
You confused the poor compiler somewhere. Set a few breakpoints, and find out what's happening. Work with Asserted Values, Run Trivial Examples, Write a Dedicated App to take just this step (Can be a Dialog based App,Call your code in OnInitApp() ). This is called 'Debugging'. The above are the steps I would take, and in that following order. I bet that Step One will lead you to the solution. It may be slow and tedious, but that's what writing software is about. Let me know how you're getting on. :rose:
Bram van Kampen
-
You confused the poor compiler somewhere. Set a few breakpoints, and find out what's happening. Work with Asserted Values, Run Trivial Examples, Write a Dedicated App to take just this step (Can be a Dialog based App,Call your code in OnInitApp() ). This is called 'Debugging'. The above are the steps I would take, and in that following order. I bet that Step One will lead you to the solution. It may be slow and tedious, but that's what writing software is about. Let me know how you're getting on. :rose:
Bram van Kampen
I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:
-
hi there, Could anybody please help me in this: I need to check the current time in my application after each message that my application receives and whenever it is midnight I reset a counter inside my program. I appreciate any ideas Thanks, Nahitan
#include < windows.h > #include < stdio.h > void main(){ SYSTEMTIME sysTime; GetLocalTime(&sysTime); printf("\nHour = %d",sysTime.wHour); //if sysTime.wHour == ...) // do...stuff }
My Articles : KitKat - A Very Simple Pseudo-RootKit (unedited) SpyNet - An Application Specific Keylogger(unedited)
-
I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:
time_t mt; time(&mt); // I would use mt =time(NULL); struct tm *now; now = localtime(&mt); tm is part of the tag Name Space. Not part of cpp as such, but still there // Works in MSVS 5.00 :) :)
Bram van Kampen
-
I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:
Thinking a bit further. struct tm is part of the C-Runtime, not CPP. That's why you need to qualify tm as a structure tag. In other words, struct tm was declared as a structure tag under 'C' it has therefore no typedef value under cpp. Regards :)
Bram van Kampen
-
time_t mt; time(&mt); // I would use mt =time(NULL); struct tm *now; now = localtime(&mt); tm is part of the tag Name Space. Not part of cpp as such, but still there // Works in MSVS 5.00 :) :)
Bram van Kampen