Functions returning current date and time?
Hey all,
Im building a simple error reporting system for my next project. I was wondering if anyone knew if there were any windows functions that return the current date and time. I''d like to add them so I can keep a running error log between builds. Thanks!
Etherstar
My Site
I should think that you could use the standard
Edit: Heh, the forum didn't like me putting "
[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on May 28, 2003 9:57:24 AM]
ctime
header. Have a look around on Google. Example:
#include <iostream>
#include <ctime>
int main()
{
time_t currentTime;
time(& currentTime);
std::cout << "Current date and time: " << ctime(& currentTime) << std::endl;
...
return 0;
}
Edit: Heh, the forum didn't like me putting "
& currentTime);
" without the spaces.[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on May 28, 2003 9:57:24 AM]
ctime standard header worked perfectly, thanks a bunch!
Etherstar
My Site
[edited by - Etherstar on May 28, 2003 10:45:06 AM]
Etherstar
My Site
[edited by - Etherstar on May 28, 2003 10:45:06 AM]
Do those functions give you the time down to the mili second?
I want to write a function to calculate frame rate by incrementing a static variable
every time the function is called.
This function will only be called at the end of all drawing.
This method wont work all the time because CurrentTime - PrevTime
may be evaluated at 1.5 seconds after PrevTime and I will loose
the 0.5 seconds and the calculation will be off.
I really need some constructive evaluation of my coding style
so that I can be come better.
How would you write your own frame rate code?
What I want is a function that will work under all circumstances.
Even if the frame rate is less than a frame per second.
I want to write a function to calculate frame rate by incrementing a static variable
every time the function is called.
This function will only be called at the end of all drawing.
UINT CalculateFrameRate(void){ static UINT Frames = 0; // Number of frames static UINT FrameRate = 0; // Frames per second static time_thingy PrevTime = 0; // Previous time time_thingy CurrentTime = GetTime(); // Get Current Time Frames++; // Increment the number of frames // This if statement subtracts CurrentTime from PrevTime to // to determine if a second has passed. if((CurrentTime - PrevTime) > 0) { FrameRate = Frames; Frames = 0; PrevTime = CurrentTime; return FrameRate; } return FrameRate;}
This method wont work all the time because CurrentTime - PrevTime
may be evaluated at 1.5 seconds after PrevTime and I will loose
the 0.5 seconds and the calculation will be off.
I really need some constructive evaluation of my coding style
so that I can be come better.
How would you write your own frame rate code?
What I want is a function that will work under all circumstances.
Even if the frame rate is less than a frame per second.
So what do you think of the method I chose to do it?
How could I improve the way I did it?
How could I improve the way I did it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement