Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Functions returning current date and time?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
I should think that you could use the standard 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]

Share this post

Link to post
Share on other sites
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.


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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!