HOW TO CONVERT DAY OF THE YEAR TO DATE IN IOS?

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
 928  View(s)
Ratings:
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

  1. Takeshi Okada

    Post:89

    Points:629
    Re: How to convert day of the year to date in ios?

    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];

    output

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

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!