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 04-24-2011, 12:48 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 54
Nekbeth is on a distinguished road
Default How to get "Total Minutes" (TIMER)

Hello, I'm trying to get the Total minutes for a Timer. I already got the seconds working. Here is how I got "Total Seconds":
Code:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];



    NSDateComponents *comps = [gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:time];



    NSInteger hour = [comps hour];

    NSInteger minute = [comps minute];

    NSLog(@"Hour:%i", hour);

    NSLog(@"minute:%i", minute);

    NSInteger secs =hour * 60 * 60 + minute * 60;





    NSNumber *elapsedSeconds = [[NSNumber alloc] initWithInt:secs];

    NSDictionary *myDict = [NSDictionary dictionaryWithObject:elapsedSeconds forKey:@"TotalSeconds"];


It might be only to change the formula, any help would be much appreciated. Thanks
Nekbeth is offline   Reply With Quote
Old 04-24-2011, 12:51 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

What exactly is the problem here? You don't know how to convert hours to minutes, or what?

hour * 60 + minute
baja_yu is offline   Reply With Quote
Old 04-24-2011, 01:04 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 54
Nekbeth is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
What exactly is the problem here? You don't know how to convert hours to minutes, or what?

hour * 60 + minute

I guess so haha, i came up with this, is it Ok?

Code:
NSInteger mins = secs / 60;
 NSNumber *elapsedMinutes = [[NSNumber alloc] initWithInt:mins];


  NSDictionary *myMin = [NSDictionary dictionaryWithObject:elapsedMinutes forKey:@"TotalMinutes"];
Nekbeth is offline   Reply With Quote
Old 04-24-2011, 04:58 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You can do
Code:
 NSNumber *elapsedMinutes = [NSNumber numberWithInt:mins];
If you do it the other way just remember to release your NSNumber.
Domele is offline   Reply With Quote
Old 04-24-2011, 07:53 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 54
Nekbeth is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
You can do
Code:
 NSNumber *elapsedMinutes = [NSNumber numberWithInt:mins];
If you do it the other way just remember to release your NSNumber.
Great, Thanks Domele
Nekbeth is offline   Reply With Quote
Reply

Bookmarks

Tags
timer

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: 346
11 members and 335 guests
dansparrow, iOS.Lover, lorrettaui53, Nobbsy, oztemel, pbart, PlutoPrime, samdanielblr, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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