iphone - How do you calculate the day of the year for a specific date in Objective-C? -


this found myself spending hours figure out , therefore want share you.

the question was: how determine day of year specific date?

e.g. january 15 15th day , december 31 365th day when it's not leap year.

try this:

nscalendar *gregorian =    [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar]; nsuinteger dayofyear =    [gregorian ordinalityofunit:nsdaycalendarunit      inunit:nsyearcalendarunit fordate:[nsdate date]]; [gregorian release]; return dayofyear; 

where date date want determine day of year for. documentation on nscalendar.ordinalityofunit method here.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -