Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chainprayer

macrumors 6502a
Original poster
Feb 10, 2008
638
2
I'm trying to assign the day of the year to a variable. For example, Jan 1 would be 1 and Dec 31 would be 365. Is there a simple way to do this?


Still working on those basic stumbling blocks as I learn obj c programming :D

Thanks! I really appreciate how helpful and amazing everyone is on the MR forums!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
One way would be to create two NSDate objects, one being right now, the other the last day of the prior year at 23:59:59 and compare them with timeIntervalSinceDate: then divide that number of seconds down to find the number of days.

Another (potentially simpler way) would be to use NSDateFormatter with a custom format string (@"DDD").

Both of these are pretty simple to find in the documentation: I suggest you make yourself familiar with it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.