Home > DeveloperSection > Forums > How to convert day of the year to date in ios?
marcel ethan
marcel ethan

Total Post:105

Posted on    November-11-2014 10:49 PM

 iPhone Ios  Objective C  Date  Time 

 1 Reply(s)
 859  View(s)
Rate this:

Currently I failed to convert a day of the year integer to a formatted string / date like mm-dd. I tried some different solution approaches, including most of the solutions which are posted here - without success.

I expect this: Today is the 359 day of the year - and it should be converted to 12-25

Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    November-12-2014 2:56 AM

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents* components = [[NSDateComponents alloc] init];

[components setDay:359];

[components setYear:2013];

[components setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSDate* day359 = [gregorian dateFromComponents:components];


2013-12-25 00:00:00 +0000

Modified On Nov-12-2014 02:56:41 AM

Don't want to miss updates? Please click the below button!

Follow MindStick