Re: Showing time differences. NSNumberFormatter?
Re: Showing time differences. NSNumberFormatter?
- Subject: Re: Showing time differences. NSNumberFormatter?
- From: Ricky Sharp <email@hidden>
- Date: Tue, 16 Jan 2007 04:33:45 -0800
On Tuesday, January 16, 2007, at 01:30AM, "Ferhat Ayaz" <email@hidden> wrote:
>
>I want to show time difference on a NSTextField which I have
>obtained with
>
> NSDate* startTime = [self valueForKey:@"startTime"];
> NSDate* endTime = [self valueForKey:@"endTime"];
> NSTimeInterval interval = [endTime timeIntervalSinceDate:startTime];
Up to this point, your code is OK.
> return [NSDate dateWithTimeIntervalSinceReferenceDate:interval];
Here's the problem. You are creating a _date_ here and not a _duration_.
>The format must be <days>:<hours>:<minutes> . The format string %d:%I:
>%M show for identical startTime and EndTime (interval is 0 in other
>words) 1:1:0. Day and hours has always one more as expected. Day will
>also not be greater then 31 because it is the day of month.
Given interval, just break it down into the components you need and use NSString's stringWithFormat to create your string.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden