So I found this answer. The way it constructs time looks weird (and imagine it without auto
), but it also doesn't work in Visual Studio 2010, because that MSVC version is too old. I don't get to chose what Visual Studio I use, so I need to stick to it. Visual studio error:
fatal error C1083: Cannot open include file: 'chrono': No such file or directory
So I had a look at the other answers, most of which declare like milion weird struct
ures, use totally::freaky<time> factories
because they are trying to get high precision time. I am pretty satisfied with time ± 5 milliseconds - I am measuring times from 100 - 5000 ms.
So how do I get approximate system/cpu millisecond time using old C++ std libraries? (MSVC2010)
PS.: In some logger files in our project, I found this:
datetimeEx(){
time_t timer;
time( &timer );
tm *t = localtime( &timer );
char tmp[32];
sprintf(tmp, "%02d%02d%02d %02d%02d%02d", t->tm_year - 100, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
log << tmp;
return log;
}
It produces time like this: 2015-11-02 16:53:57:389
I played with it, but I couldn't get difference between two times.