Advertisement

How do I get the current time?

Started by June 07, 2002 10:27 PM
3 comments, last by Shenron 22 years, 6 months ago
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;
}
 
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]
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Look up preprocessor definitions __TIME__, __TIMESTAMP__, __DATE__, et al.

Good luck!



MatrixCubed
http://MatrixCubed.cjb.net

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.
---visit #directxdev on afternet <- not just for directx, despite the name
ahh..i got it. thanks a lot.

[edited by - Shenron on June 8, 2002 1:32:07 AM]

This topic is closed to new replies.

Advertisement