Quantcast
Viewing all articles
Browse latest Browse all 37

Answer by Sargis for How can I get the current day of the current year in integer in objective c ios

Use this.

//Assuming your calendar is initiated like thisNSCalendar *_calendar = [NSCalendar currentCalendar];NSInteger yearlyDay;//Fetch the weekOfYear numberNSInteger weekOfYear = [_calendar component:NSCalendarUnitWeekOfYear fromDate:[NSDate date]];weekOfYear--;//Fetch the weekDay numberNSInteger weekDay = [_calendar component:NSCalendarUnitWeekday fromDate:[NSDate date]];yearlyDay = weekOfYear*7 + weekDay;NSLog(@"%d", yearlyDay);

or this.

NSCalendar *gregorian =    [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];    NSUInteger dayOfYear =    [gregorian ordinalityOfUnit:NSCalendarUnitDay                         inUnit:NSCalendarUnitYear forDate:[NSDate date]];    NSLog(@"%d", dayOfYear);

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>