Tag: nsdate

String description of NSDate

I have the following code: [ [NSDate date] descriptionWithLocale: @”yyyy-MM-dd” ] I want it to return a date in the following format: “2009-04-23” But it returns: Thursday, April 23, 2009 11:27:03 PM GMT+03:00 What am I doing wrong? Thank you in advance.

Modifying NSDate to represent 1 month from today

I’m adding repeating events to a Cocoa app I’m working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the following code to modify the date: [NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))] I know how many months have passed since the event was repeated but I can’t […]

Get Current date & time with

My system’s date time is 26 May 22:55 but when i get date with [NSDate date] date time is 27 May 02:35 is it because of time zone ? if yes how to solve this problem, that when i get date time, give me the date of my system and doesn’t check time zone

How to get all the days/dates in current week, this month, this year using the current date (today) in iPhone

In my application i have to show list of working hours by date in a table view, Here i have 5 scenarios Today’s projects, working hours Selected date projects, hours Cureent week (sunday-saturday) Current month (working hours in january, February if it is feb march if it is march) Current year (all working hours in […]

NSDateFormatter won't format strange date string

So I have a date string I receive that looks like this: “2013-03-20T21:13:26-7:00” that I receive from a web back end. I have no control over the back end, just a fyi. My preference would be to have the date formatted like this: 9:13pm at 3/20. When I do the following NSDateFormatter *dateFormatter = [[NSDateFormatter […]

NSSortdescriptor ineffective on fetch result from NSManagedContext

I’m trying to sort my NSFetchRequest result using a NSSortdescriptor using a key pointing to a NSDate value. My fetch results come out totally random for no clear reason. The NSManagedObjectContext I’m using is updated with a save from a nested child context created on a subclass of NSOperation. I know all this is done […]

NSDateFormatter – 1 day incorrect?

I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter […]

Comparing time in NSDate

I am trying to compare the time from two NSDate objects but am getting the wrong answer. I think it is because when using the NSDate compare methods it is also including the date. I just want to ignore the date and compare the times. How can this be done?

Number of weeks in month

I have the following code: NSDate *dateNow = [[NSDate alloc] init]; NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow]; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *date1 = [[NSDate alloc] init]; NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1]; // Get conversion to months, days, hours, minutes unsigned int unitFlags = […]

NSDate from NSString gives null result

I am using following code to generate NSDate -> NSString +(NSString *)getCurrentTime { NSDate *now = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”dd-MM-yyyy hh:MM:SS a”]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString* str =[dateFormatter stringFromDate:now]; [dateFormatter release]; NSLog(@”%@”,str); return str; } everything is fine in above code. I am using above code to store string […]