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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-27-2011, 12:27 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 36
BrightMedia is on a distinguished road
Default Creating timer to count seconds and tenths of seconds

Hello,

Does anyone know how to create a timer that counts seconds and tenths of seconds in the format hours:minuts:seconds:tenths of seconds?
BrightMedia is offline   Reply With Quote
Old 01-02-2012, 02:34 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

To start off, you should create a timer which fires every 0.1 sec. Then a variable elapsedTime should get incremented by 0.1 whenever the timer ticks. Then:

Code:
hours = elapsedTime / 3600;
minutes = (elapsedTime / 60) % 60;
seconds = elapsedTime % 60
tenths of seconds = elapsedTime - floorf(elapsedTime);
mariano_donati is offline   Reply With Quote
Old 01-02-2012, 03:24 AM   #3 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Sorry marianio but that's not the correct approach. You should use NSDate's timeIntervalSinceDate method. When you start your timer, set an ivar named startDate. In the timer method, call timeIntervalSinceDate passing in startDate on the current date. Then, assuming mariano's way of calculating the variables are correct, use his code on the returned NSTimeInterval.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 01-02-2012, 09:15 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

Domele: thanks for pointing that out, I agree, that is the correct approach.
mariano_donati is offline   Reply With Quote
Old 01-09-2012, 10:25 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 36
BrightMedia is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Sorry marianio but that's not the correct approach. You should use NSDate's timeIntervalSinceDate method. When you start your timer, set an ivar named startDate. In the timer method, call timeIntervalSinceDate passing in startDate on the current date. Then, assuming mariano's way of calculating the variables are correct, use his code on the returned NSTimeInterval.
Thanks a lot everybody!
BrightMedia 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: 385
10 members and 375 guests
apatsufas, comicool, Creativ, Dalia, dansparrow, husthlj, LunarMoon, mer10, Murphy, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

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