Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 11, 2009, 07:31 AM   #1
Stunner
macrumors newbie
 
Join Date: Sep 2009
Confused By the Output of My Program

Ey guys, I am a little confused by the output I am getting from timeIntervalSinceDate. Here is the code I have:
Code:
NSDate *prevDate;
	for (NSDate *thisDate in self.arrayOfTimes) {
		NSLog(@"item: %@",thisDate);
		if (counter > 1) {
			NSLog(@"item: %d",[thisDate timeIntervalSinceDate:prevDate]);
		}
		prevDate = thisDate;
	}
And here is my output in console:
Code:
2009-11-11 05:25:39.740 WTC[82810:20b] counter: 1
2009-11-11 05:25:39.742 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:25:41.087 WTC[82810:20b] counter: 2
2009-11-11 05:25:41.088 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:25:41.089 WTC[82810:20b] item: 0
2009-11-11 05:25:41.089 WTC[82810:20b] item: 2009-11-11 05:25:41 -0800
2009-11-11 05:25:41.089 WTC[82810:20b] item: -1610612736
2009-11-11 05:25:43.481 WTC[82810:20b] counter: 3
2009-11-11 05:25:43.482 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:25:43.484 WTC[82810:20b] item: 0
2009-11-11 05:25:43.485 WTC[82810:20b] item: 2009-11-11 05:25:41 -0800
2009-11-11 05:25:43.485 WTC[82810:20b] item: -1610612736
2009-11-11 05:25:43.486 WTC[82810:20b] item: 2009-11-11 05:25:43 -0800
2009-11-11 05:25:43.486 WTC[82810:20b] item: -402653184
2009-11-11 05:25:49.757 WTC[82810:20b] counter: 4
2009-11-11 05:25:49.758 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:25:49.759 WTC[82810:20b] item: 0
2009-11-11 05:25:49.760 WTC[82810:20b] item: 2009-11-11 05:25:41 -0800
2009-11-11 05:25:49.761 WTC[82810:20b] item: -1610612736
2009-11-11 05:25:49.761 WTC[82810:20b] item: 2009-11-11 05:25:43 -0800
2009-11-11 05:25:49.762 WTC[82810:20b] item: -402653184
2009-11-11 05:25:49.762 WTC[82810:20b] item: 2009-11-11 05:25:49 -0800
2009-11-11 05:25:49.763 WTC[82810:20b] item: 671088640
2009-11-11 05:25:53.821 WTC[82810:20b] counter: 5
2009-11-11 05:25:53.822 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:25:53.822 WTC[82810:20b] item: 0
2009-11-11 05:25:53.823 WTC[82810:20b] item: 2009-11-11 05:25:41 -0800
2009-11-11 05:25:53.824 WTC[82810:20b] item: -1610612736
2009-11-11 05:25:53.824 WTC[82810:20b] item: 2009-11-11 05:25:43 -0800
2009-11-11 05:25:53.825 WTC[82810:20b] item: -402653184
2009-11-11 05:25:53.826 WTC[82810:20b] item: 2009-11-11 05:25:49 -0800
2009-11-11 05:25:53.826 WTC[82810:20b] item: 671088640
2009-11-11 05:25:53.826 WTC[82810:20b] item: 2009-11-11 05:25:53 -0800
2009-11-11 05:25:53.827 WTC[82810:20b] item: -1073741824
2009-11-11 05:26:00.567 WTC[82810:20b] counter: 6
2009-11-11 05:26:00.568 WTC[82810:20b] item: 2009-11-11 05:25:39 -0800
2009-11-11 05:26:00.569 WTC[82810:20b] item: 0
2009-11-11 05:26:00.569 WTC[82810:20b] item: 2009-11-11 05:25:41 -0800
2009-11-11 05:26:00.570 WTC[82810:20b] item: -1610612736
2009-11-11 05:26:00.570 WTC[82810:20b] item: 2009-11-11 05:25:43 -0800
2009-11-11 05:26:00.571 WTC[82810:20b] item: -402653184
2009-11-11 05:26:00.571 WTC[82810:20b] item: 2009-11-11 05:25:49 -0800
2009-11-11 05:26:00.572 WTC[82810:20b] item: 671088640
2009-11-11 05:26:00.573 WTC[82810:20b] item: 2009-11-11 05:25:53 -0800
2009-11-11 05:26:00.574 WTC[82810:20b] item: -1073741824
2009-11-11 05:26:00.575 WTC[82810:20b] item: 2009-11-11 05:26:00 -0800
2009-11-11 05:26:00.575 WTC[82810:20b] item: -671088640
I am wondering why the program is printing out positive and negative numbers such as: -671088640 and 671088640. And how would I go about converting these values into seconds? Thanks!
Stunner is offline   0 Reply With Quote
Old Nov 11, 2009, 08:14 AM   #2
ChOas
macrumors regular
 
Join Date: Nov 2006
Location: The Netherlands
timeIntervalSinceDate returns an NSTimeInterval, NSTimeInterval is a double, you are trying to print an integer... Overflow is biting you.

Try:

Code:
NSLog(@"interval: %g",[thisDate timeIntervalSinceDate:prevDate]);
ChOas is offline   0 Reply With Quote
Old Nov 11, 2009, 09:00 PM   #3
Stunner
Thread Starter
macrumors newbie
 
Join Date: Sep 2009
Quote:
Originally Posted by ChOas View Post
timeIntervalSinceDate returns an NSTimeInterval, NSTimeInterval is a double, you are trying to print an integer... Overflow is biting you.

Try:

Code:
NSLog(@"interval: %g",[thisDate timeIntervalSinceDate:prevDate]);
Awesome, thank you. By the way, does there happen to be a page that lists what should be used when printing different values? Such as %d for integers, %g for time values, etc. Thanks again.
Stunner is offline   0 Reply With Quote
Old Nov 12, 2009, 01:37 AM   #4
ChOas
macrumors regular
 
Join Date: Nov 2006
Location: The Netherlands
Quote:
Originally Posted by Stunner View Post
Awesome, thank you. By the way, does there happen to be a page that lists what should be used when printing different values? Such as %d for integers, %g for time values, etc. Thanks again.
After some searching (you can do this too, really ) I found these for you:

http://developer.apple.com/mac/libra...TP40004265-SW1

http://www.opengroup.org/onlinepubs/...ns/printf.html
ChOas is offline   0 Reply With Quote
Old Nov 12, 2009, 04:09 AM   #5
Stunner
Thread Starter
macrumors newbie
 
Join Date: Sep 2009
Awesome, thanks.
Stunner is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
confused by the multitude of Internet connections in OS X! kdum8 OS X 4 Oct 14, 2010 04:01 AM
How do i separate my itunes program and the location of my music? NIPRING Mac Applications and Mac App Store 1 Feb 24, 2010 02:37 PM
Why some of my programs are named "null" in the activity monitor? yudilks OS X 4 Feb 3, 2009 07:30 AM
Is There a Program to Decrease the Size of My Jpeg's???? SamIchi Mac Applications and Mac App Store 8 Feb 20, 2005 05:14 PM
I'm so confused in the delay of my order... acceber Wasteland 2 Oct 1, 2004 10:42 AM


All times are GMT -5. The time now is 05:18 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC