Archived

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

Shenron

How do I get the current time?

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
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