Day of the year

Discussion in 'iOS Programming' started by chainprayer, Jan 11, 2010.

  1. chainprayer macrumors 6502a

    Joined:
    Feb 10, 2008
    #1
    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!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     

Share This Page