Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 11, 2009, 08: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, 09: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, 10: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, 02: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, 05: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

Similar Threads
thread Thread Starter Forum Replies Last Post
Confused on what I need... cynics Buying Tips and Advice 5 Jul 8, 2013 01:39 AM
Late 2012 27" iMac output to my HD TV ~ confused iF34R iMac 4 Jun 6, 2013 08:10 PM
not getting any output from my program?? sg001 Mac Programming 5 Aug 10, 2012 04:54 PM
Confused b3thomso iPad Tips, Help and Troubleshooting 3 Jul 12, 2012 01:21 PM
My solution for "No Sound Output to MacBook Speakers" - Re-route Sound Input / Output grantdoug MacBook Pro 1 Jun 27, 2012 11:44 AM

Forum Jump

All times are GMT -5. The time now is 03:39 AM.

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

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