Jump to content
  • Advertisement

Archived

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

Shenron

How do I get the current time?

This topic is 5886 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

How can I get the current time? I tried something simple like this but I couldn''t get it to work. I could''t find any documentation on it either but I probably didnt look in the right place. Thanks.
#include <iostream>
#include <time.h>
using namespace std;

void main()
{
    float time;
    time = time();
    cout << time;
}
 

Share this post


Link to post
Share on other sites
Advertisement
Try the C version (probably you should use ctime and std:: for C++)

    
#include <time.h>


time_t time;
time(&time);
struct tm current_time = *localtime(&time);

or Win32 version

  
SYSTEMTIME CurrentTime;
GetSystemTime(&CurrentTime);



[edited by - IndirectX on June 7, 2002 12:27:48 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by MatrixCubed
Look up preprocessor definitions __TIME__, __TIMESTAMP__, __DATE__, et al.


These macros will give you the compile timestamp, not the current time at program execution.

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!