how to extract the milliseconds
i have been searching the net for 3hours now on how to solve my problem about how to extract the milliseconds from an input but still found no answers. sigh! :(. Im trying my luck here that maybe experts have an idea about this.
the input i have is in type time_t. We know we can get the hours, minutes and seconds thru localtime call. but how about the milliseconds?
I saw ftime, gettimeofday, clock_gettime but theyre not helping me, they all return the current time.
can you help me?
Thanks in advance.
Re: how to extract the milliseconds
Quote:
Originally Posted by
jp185088
the input i have is in type time_t. We know we can get the hours, minutes and seconds thru localtime call. but how about the milliseconds?
I don't think time_t stores milliseconds. It may be compiler dependent, but I think in most cases it only stores seconds.
If you need more accurate time measures have a look at http://www.codeguru.com/forum/showthread.php?t=291294.
Re: how to extract the milliseconds
oh i see. it was originally in type long long then i converted it to unix time using
Code:
void timevmstounix( long long *vmstimein, time_t *epochout )
{
long long timevalue = *vmstimein;
timevalue -= 0x07c95674beb4000ull;
timevalue /= 10000000;
*epochout = (time_t) timevalue;
return;
}
so if time_t only holds until seconds, then timevalue above should not be divided by 10000000? am i right?
then if i divide the timevalue by only 10000, i should get the milliseconds. is it?
Re: how to extract the milliseconds
Use the High performance timer! This is a high resolution timer,
that can do microseconds too!
QueryPerformanceFrequency will return counts per second.
PHP Code:
int ntime=0;
LARGE_INTEGER ntime1,ntime2;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&ntime1);
//...do workIn hero
dosomefunction();
QueryPerformanceCounter(&ntime2);
//get ntime in milliseconds
ntime = (ntime2.QuadPart-ntime1.QuadPart)/(freq.QuadPart/1000);
//Or for microseconds:
//ntime = (ntime2.QuadPart-ntime1.QuadPart)/(freq.QuadPart/1000000);
HTH,
ahoodin
Re: how to extract the milliseconds
If your using windows, you can use the COleDateTime class which uses a double to represent time from some epoch. The COleDateTime class has the function GetAsSystemTime to read the date/time into a SystemTime which holds milliseconds. Unfortunately the milliseconds are not read. This is a bug that Microsoft is aware of. However, there is a fix for this if you want to go this route by way of VariantTime.
http://www.codeproject.com/KB/dateti...WMillisec.aspx
This system works for me.
Re: how to extract the milliseconds
My method will get you microseconds or even nanoseconds as it retrieves the value from the high-resolution performance calculator.
It is a better method.
Re: how to extract the milliseconds
thanks to all your replies. I am coding in linux 64bit. sorry i didnt mention it on my first post.
I already got the answer to my problem. My reply to D_Drmmr as you can see solved the problem! :) how clever. hehe
Hope this thread can help to anyone asking something like this soon. Thank you guys!
Re: how to extract the milliseconds
Quote:
Originally Posted by
jp185088
thanks to all your replies. I am coding in linux 64bit. sorry i didnt mention it on my first post.
:mad:
So why did you post in the Visual C++ forum??? This forum is for Microsoft Visual C++, not Linux. Next time, post in the non-Visual C+ forum.
Regards,
Paul McKenzie
Re: how to extract the milliseconds
oh. maybe the moderators can help me transfer this thread to the correct forum.
Thanks!
Re: how to extract the milliseconds
Quote:
Originally Posted by
jp185088
oh. maybe the moderators can help me transfer this thread to the correct forum.
Thanks!
The SPAM file. :D