Advertisement Jump to content
Sign in to follow this  

system time

This topic is 693 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 to get cross platform time? newdate for a file is ok but current time is something in 2106. So I need the current time (date) as integer.

    struct stat st, attrib;
    int date = time(0);//or the same with: st.st_mtime;

    stat(InFileLocHw.c_str(), &attrib);         //2. get the attributes of afile.txt
    int newdate = attrib.st_mtime;

Many thanks


Share this post

Link to post
Share on other sites

Usual tactic is to have a generic function to get time in your application that you use everywhere, and implement that function for every platform you want to support.

C/C++ compilers have a bunch of #define-ed variables that you can use to see what platform you are compiling for, and to select the piece of code that transforms whatever time representation the platform has to the time that you use throughout your application.



int getTime()
#ifdef WIN32
  // code for windows 32 bit
  // code for other platforms

Share this post

Link to post
Share on other sites

Depends on what you want to do with the time.  Do you just need a timestamp, or are you looking for a high resolution game timer?

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!