system time

Started by
2 comments, last by 21st Century Moose 7 years, 1 month ago

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

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
}

std::chrono::system_clock is without doubt the least painful way to get time cross-platform in C++. There's a conversion function to time_t listed on that page, too.

Thanks

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?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement