-
July 26th, 2011, 08:53 AM
#1
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.
-
July 26th, 2011, 09:01 AM
#2
Re: how to extract the milliseconds
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
July 26th, 2011, 09:08 AM
#3
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?
Last edited by jp185088; July 26th, 2011 at 09:33 AM.
-
July 26th, 2011, 11:51 AM
#4
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
Last edited by ahoodin; July 26th, 2011 at 11:53 AM.
ahoodin
To keep the plot moving, that's why.
-
July 26th, 2011, 12:14 PM
#5
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.
-
July 26th, 2011, 12:41 PM
#6
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.
Last edited by ahoodin; July 26th, 2011 at 12:43 PM.
ahoodin
To keep the plot moving, that's why.
-
July 27th, 2011, 08:22 AM
#7
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!
-
July 27th, 2011, 08:49 AM
#8
Re: how to extract the milliseconds
Originally Posted by jp185088
thanks to all your replies. I am coding in linux 64bit. sorry i didnt mention it on my first post.
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
-
July 27th, 2011, 08:59 AM
#9
Re: how to extract the milliseconds
oh. maybe the moderators can help me transfer this thread to the correct forum.
Thanks!
-
July 27th, 2011, 11:30 AM
#10
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|