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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

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

openssl - Load PKCS#8 binary key into Ruby -