Main Topics
Browse All TopicsHow do I get the computer time in seconds and milliseconds since the epoch?
I am using XCode and coding in C and running on Intel computers. I want to use ftime() but I can't work out how to use it!
I have tried to compile the code given as an answer to this question:
http://www.experts-exchang
but this won't compile:
I get 1 error and 1 warning:
error: storage size of 'timebuffer' isn't known
warning: unused variable 'timebuffer'
I really need to sort this out for my MIDI sequencer project. Any help would be great.
All I need is a way to get system time in seconds and milliseconds!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Wow that was quick thanks evilrix!
Ok thats compiling and running fine now but I just want to print seconds and milliseconds. In the timeb structure millitm is an unsigned short and seconds is part of time_t.
How do you print these using printf? something like this?:
printf("Seconds:%d,Millise
>> Remove leading underscore from timeb and ftime and it compiles.
That really depends on your compiler. My compiler (gcc) has the versions with the underscore too.
Check whether you have the <sys/timeb.h> header, and how it defines the struct needed for the ftime function.
Note that you shouldn't use the ftime function, but should use time instead (if seconds are enough).
http://www.cplusplus.com/r
If you need micro-seconds, then take a look at gettimeofday :
http://www.opengroup.org/o
The purpose for this is to be able to get the time when a MIDI event has happened and then write it to a file for playback.
First I'd have to get the time of the start of the program. When a MIDI event happens I get the time again and work out how long after the start that was and write it to a file along with the MIDI info (note number and velocity). Then when I play it back I get the start time and then play each note after the correct amount of time has passed.
How do I access and display the number of seconds?!
I can print the number of milliseconds like this:
Even though ftime() is obsolete I am only doing this is a 1st year university assignment, this isn't going to be used by the public, just marked by my tutor. Everyone else decided to use usleep() in a while loop to work out time but this way is far easier to use especially for polyphonic sequencing.
Business Accounts
Answer for Membership
by: evilrixPosted on 2008-04-28 at 04:31:57ID: 21452983
Remove leading underscore from timeb and ftime and it compiles.
Select allOpen in new window