Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

to show sub-second time in C

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do we display sub-second value when we display current time, something like hh:mm:ss:ss? I tried gettimeofday() which shows microseconds from 1 Jan 1970 but how do we show time?? struct tm doesn't help either, as there is not anything beyond seconds in struct tm.
 
I don't understand you comment about struct tm.

struct tm has 2 fields
uint tv_secs ;
uint tv_usecs;

the tv_usecs is microseconds.

On my UNIX system this is usually in Milli seconds because the last 3 digits always seem to be '000'.

To get much lower you will probably have to access the kernel time in ticks.

---
 
tv_usecs is not used up to now, because the Data-Range of a 32-Bit variable ist too small.

Actually there is no importance to use this feature on an absolute time, because of computer synchronisation problems. If you use it do measure time differences you may use any internal time Stamp as a reference.

hnd
hasso55@yahoo.com

 
The standard C time libraries don't provide millisecond resolution. You'll have to use a compiler extension for this. In other words, the tv_usecs member is not guaranteed to be provided by all C compilers.
Russ
bobbitts@hotmail.com
 
Good point. So I guess the next question is what System are you compiling you application for. Maybew there is a platform specific service avaialble since Standard C doesn't seem to support it.

iuf you need soamething not so platform specific, you might check to see if there is a GNU time implementation of Hi Res time. GNU tends to support multiple platforms from a single API.


----

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top