Tag: nscalendar

NSDateComponents weekOfYear returns wrong value

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierISO8601]; [calendar setTimeZone:[NSTimeZone defaultTimeZone]]; [calendar setFirstWeekday:2]; [calendar setMinimumDaysInFirstWeek:1]; NSDateComponents *mockTodayComponents = [[NSDateComponents alloc] init]; mockTodayComponents.day = 28; mockTodayComponents.month = 12; mockTodayComponents.year = 2015; NSDate *date = [calendar dateFromComponents:mockTodayComponents]; NSDateComponents *c = [calendar components:NSCalendarUnitWeekOfYear | NSCalendarUnitYearForWeekOfYear fromDate:date]; NSInteger week = [c weekOfYear]; week returns 1 instead of 53 and ofcoaurse the […]

How can I find out whether an NSDate is a business day?

How can I find out whether an NSDate is a business day? That is to say, whether or not it is a weekend according to the user’s current locale and calendar settings – so not hardcoded to just be Monday to Friday? NSCalendar has a firstWeekday property, but that just seems to be a presentational […]

Objective-C/iOS: Get date for specific day in week (sunday)

I need to get the date of a specific day (Sunday) in the current week. I use this date to determine if some weekly resetting should occur, and I do some calculations on last reset date is before sundays date etc. This has in principal been ask and answered many times, and my solution has […]

Converting NSDate from a calendar to another

I’m having trouble here. Took me hours but no use. Please keep in mind I checked the heck of StackOverFlow for a fix but there isn’t any. When I convert the _date Object from Gregorian to Hijri it does not convert. I know that because when I print it it still gives me the Gregorian […]

Count of a specific weekday occurring between two NSDates

How can I find the count of a specific weekday occurring between two NSDates? I have searched for quite a while but came up with only solution in which number of total weekdays have been counted, not only the one specific week day.

NSDateFormatter can't parse '1988-04-10' to NSDate instance in iOS 6 . Is it a bug?

I encountered a stranger question. NSDateFormatter can’t parse 1988-04-10 to NSDate instance in iOS 6. But it works in iOS 4 and iOS 5. Is it a bug? Following is the code. It is very simple. NSArray *values = @[@”1988-04-09″, @”1988-04-10″, @”1988-04-11″]; NSDateFormatter* df = [[NSDateFormatter alloc] init]; NSLocale *posixLocale = [[NSLocale alloc] initWithLocaleIdentifier:@”en_US_POSIX”]; [df […]

In Objective-C, to get the current hour and minute as integers, we need to use NSDateComponents and NSCalendar?

I’d like to get the current hour and minute as integers. So if right now is 3:16am, I’d like to get the two integers: 3 and 16. But it looks like [NSDate date] will give the number of seconds since 1970, or it can give a string of the current time representation, but there is […]

Schedule UILocalNotification everyday at specific time

I am using below piece of code to schedule a localnotification at specific time. But the notification is repeating for every minute instead of after one day. Whether i have missed any notification settings. My timezone is (Asia/Calcutta (IST) offset 19800) and using iPhone 4s. – (void)applicationDidEnterBackground:(UIApplication *)application { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ; […]

Changing Gregorian Month and Days names to Islamic? NSDate

I’m trying to display the Islamic current day name , month name. I used NSLocale to set the region to ar_SA, however it’s just translating the day and month names from English to Arabic. Output I’m getting in Arabic: ١٢ الأحد ، اكتوبر ، ٢٠١٢ which in English is Sunday, October 28, 2012 Output I […]

iPhone NSDate eg. next Friday

I want to create a function which results the date of next Friday but I have no plan how to do it. Has anyone a good hint to me ?