Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-21-2011, 11:53 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 144
iAppDev is on a distinguished road
Default milliseconds timer help plz

so I've been working on making a timer and everything is good except one. I can't get the format of how to have it show and function in milliseconds.
currently i have it as seconds.
Code:
    //this is the format of the counter
    gamesTimer.text = [NSString stringWithFormat:@"%d", MainInt];
 
    //this is the counter in seconds
MainInt += 1;
how can i have it to show in milliseconds and seconds.

like this
seconds milliseconds
0:00 where each 10 millisecond equals 1 second.

thanks in advance
iAppDev is offline   Reply With Quote
Old 11-21-2011, 01:18 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by iAppDev View Post
so I've been working on making a timer and everything is good except one. I can't get the format of how to have it show and function in milliseconds.
currently i have it as seconds.
Code:
    //this is the format of the counter
    gamesTimer.text = [NSString stringWithFormat:@"%d", MainInt];
 
    //this is the counter in seconds
MainInt += 1;
how can i have it to show in milliseconds and seconds.

like this
seconds milliseconds
0:00 where each 10 millisecond equals 1 second.

thanks in advance

You can't increment a timer and have it work in milliseconds. NSTimer is only accurate to somewhere around 50 milliseconds.

What you want to do is record the start time for something you want to time, then compare that value to the new time. Something like this:


Code:
NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
//Do something time-consuming

NSTimeInterval elapsed = [NSDate timeIntervalSinceReferenceDate] - startTime;

int seconds = elapsed; //Truncate the integer part.
int milliseconds = floor((elapsed - seconds)* 1000);//Round to the nearest millisecond.
The code above will give you integer seconds and integer milliseconds.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-21-2011, 02:02 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 144
iAppDev is on a distinguished road
Default

I'm sorry Duncan but i can't understand the code. i understand that i can put it into my countup method but how can i combine it with my gameTimer method?

thanks
iAppDev is offline   Reply With Quote
Old 11-21-2011, 06:13 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by iAppDev View Post
I'm sorry Duncan but i can't understand the code. i understand that i can put it into my countup method but how can i combine it with my gameTimer method?

thanks
What method contains the code you posted? And how is it being called? What are you trying to time?

Post the whole method that includes that timer int, and also show how you set up the timer that calls it.

BTW, you said every 10 milliseconds equals 1 second. There are 1,000 milliseconds in a second, not 10.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-21-2011, 07:05 PM   #5 (permalink)
Registered Member
 
Objective Zero's Avatar
 
Join Date: Oct 2010
Posts: 1,210
Objective Zero is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
BTW, you said every 10 milliseconds equals 1 second. There are 1,000 milliseconds in a second, not 10.
I think what he means is that he wants to represent 1 as 100.
__________________
Questions?

Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
Objective Zero is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 390
15 members and 375 guests
7twenty7, chiataytuday, Clouds, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, jeroenkeij, leostc, mbadegree, Murphy, QuantumDoja, Sami Gh
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0