LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2005, 02:22 AM   #1
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Rep: Reputation: 15
how can get the 'millisecond'


hi ,all
I want to get the system's time ,and need millisecond level.so how can i do it.
as I know ,the function
Code:
int gettimeofday ( struct timeval * tv , struct timezone * tz )
will store the second and millisecond into the struct timeval.
tv->tv_sec; /*second*/
tv-> tv_usec; /*millisecond*/

but when I print the 'tv->tv_usec', i got a long number,it's not the millisecond now. So how I can convert the long number to a millisencond between 0-99
Or is there any other method can I get the millisecond.thank you for all your suggestion!
 
Old 08-08-2005, 02:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
since when was a millisecond a number between 0 and 99??

anywho... usec is a microsecond, the top 3 significant digits are your microsecond, so divide it by 1000 and truncate it...
 
Old 08-08-2005, 03:14 AM   #3
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
I am sorry that I've make some mistake ,millisecond is between 0-999.
Since I know
microsecond = 1/1000000 second
millisecond = 1/1000 second
In a word ,I want got the two number following the second.we can see the string in some clock:
Code:
16:12:23.50
and we call them HOUR:MINUTE:SECOND.** ,but I don't know how can we call the last '50'.
I my porgram I just want to got the 50,,ok, do you understand me?
 
Old 08-08-2005, 07:37 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
so liek i said, that should be most significant digits of the usec value. if you have 0.50 seconds that would be 500000 usec
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU consumed time with millisecond resolution. lofrbo Linux - Software 2 11-18-2005 10:46 AM
millisecond pause oopicmaster Programming 1 10-10-2003 12:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration