Tag: nsdate

How to get the date a week in the past from today?

I know how to get the date in iOS. I need to find last weeks date. So for example if today is 05/27/2011, I need to be able to get 05/20/2011 Thanks

How to parsing NSDate to RFC 822 always use in English?

I need to PUT a RESTful to server. the Date must use like Sat, 19 Jan 2013 04:09:58 GMT. in objc I wrote this: NSDateFormatter* _GMTDateFormatter = [[NSDateFormatter alloc] init]; [_GMTDateFormatter setDateFormat:@”EEE, dd MMM yyyy HH:mm:ss”]; [_GMTDateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString* theDate = [_GMTDateFormatter stringFromDate:[NSDate date]]; theDate = [theDate stringByAppendingString:@” GMT”]; NSLog(@”%@”,theDate); it will be output […]

NSDate isMemberOfClass: returns false?

This question already has an answer here: usage of isMemberOfClass; returning false 3 answers

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 to implment laps in Stop Watch iphone app

I am building one application which has stop watch as its accessory function. I am trying to do something very similar to iOS stop watch. I got stop, reset functionality working but I could not get start (once it stop and user click on start) and lap functions working properly. I tried to look around […]

PHFetchResults date filter not generating correct results for time range

I am trying to fetch images from photo library within the range of two dates and I am getting the images successfully. Using PHAsset Library Now the problem is that am not able to get images between two times of the same day like between 12:10PM to 12:30PM Using below code NSDate *startDate = [self […]

NSDate : timeIntervalSinceNow crash

I want to display, on screen, the elapsed time since some event. I have a member variable NSDate *_startTime; I allocate it (and initiate a timer) like so: _startTime = [NSDate date]; _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(clock) userInfo:nil repeats:YES]; My clock function gets called fine but when I attempt to find the elapsed time […]

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 […]

Check if an array of custom objects contains an object with a certain date

I have an array of event objects. The object has several attributes. One of the attributes is an NSDate eve_date. Now I want to check if that array of objects contains a certain NSDate d I’m doing the following if([[matches valueForKey:@”eve_date”] containsObject:d]){ NSLog(@”contains object”); }else{ NSLog(@”does not contains object”); } But this is not working. […]

Still having NSDateFormatter result issues even with NSTimezone properly set, why?

The result is still a day before, I’m just asking myself why, because the NSTimeZone is properly set and is the right one for my country (italy, rome) here’s my stub of code, any ideas? NSString *dateString = @”03/07/2008″; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setFormatterBehavior:[NSDateFormatter defaultFormatterBehavior]]; [formatter setDateFormat:@”dd/MM/yyyy”]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setTimeZone:[NSTimeZone […]