Advertisement Jump to content
Sign in to follow this  
Jinx3d1

time and date macros...

This topic is 4900 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 guys, just a quick question... I used to a predefined macro which would give the time and date. I can not remeber what it was for the life of me, any idea? Thnx.

Share this post


Link to post
Share on other sites
Advertisement
lol.. I thought about it just a few minutes ago and realized I already know __TIME__ and __DATE__ but those only give the time and date at compile time. There was another one though that would give you the time and date at run time... hrm...
Im going to try __TIMESTAMP__ thnx.

Share this post


Link to post
Share on other sites
They're predefined preprocessor macros, hence compile time only. Beware that __TIMESTAMP__ is a non-standard extension and may not some compilers.

To get a runtime date string you can call the ctime() function instead.
const char *timestamp(void) {
time_t tval = time(NULL);
return ctime(&tval);
}

Share this post


Link to post
Share on other sites
There's no real point in having a macro that would give the time and/or date at runtime. Macros are parsed into C/C++ code at compile time by the preprocessor, so what point wrapping a function call into a macro?

There are several standard C library functions for working with the date and time; see this reference for quick details.

Cheers,
Twilight Dragon

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!