• Advertisement
Sign in to follow this  

system time

This topic is 420 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

Hi

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
Advertisement

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.

 

Edit:

int getTime()
{
#ifdef WIN32
  // code for windows 32 bit
#else
  // code for other platforms
#endif
}

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