Re: Showing time differences. NSNumberFormatter?
Re: Showing time differences. NSNumberFormatter?
- Subject: Re: Showing time differences. NSNumberFormatter?
- From: Nir Soffer <email@hidden>
- Date: Tue, 16 Jan 2007 15:08:08 +0200
On Jan 16, 2007, at 09:29, Ferhat Ayaz 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];
return [NSDate dateWithTimeIntervalSinceReferenceDate:interval];
Seems ok.
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.
You can format a date with NSDateFormatter. Here is an example code
that does that (using another format, but you can handle that):
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init]
autorelease];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setDateFormat:@"EEE, MMM d, hh mm a"];
return [formatter stringFromDate:[NSDate date]];
The format string uses ICU format, not standard unix date formating
format.
Best Regards,
Nir Soffer
_______________________________________________
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