Jump to content
  • Advertisement
Sign in to follow this  
Jinx3d1

time and date macros...

This topic is 4833 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.

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!