nsdate

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 ca...

Dealing with objects returned from cocoa convenience methods

I'm having a lot of issues with NSDate objects being prematurely deallocated. I suspect that the issues may be related to the way that I deal with the objects returned from NSDate convenience methods. I think that my showDate property declaration in the JKShow class should be "retain", but changing it to assign or copy seems to have no e...

Convert NSDate to NSString

How do I convert an NSDate to an NSString so that only the year in @"yyyy" format is output to the string? ...

HTTP date format to NSDate

I have a date string (well, NSData, but that's easy to convert to a string) that's in what I believe is the format the HTTP standard uses: Mon Apr 17 19:34:46 UTC 2006 Is there any better (i.e. less error-prone) way to parse that than specifying the format string by hand in an NSDateFormatter? (My application is an iPhone app, but I ...

UIDatePicker and NSDate

I have an NSDate that I get from a UIDatepicker. IBOutlet UIDatePicker *dueDate; NSDate *selectedDate = [dueDate date]; how do I retrieve the month from dueDate in the form of an int? (1 for Jan, 2 for Feb, etc) ...

add NSTimeInterval to NSDate in cocoa

I've got a NSDate that represents a specific time. The format of that date is hhmmss. I want to add an NSInterval value (specified in seconds) to that time value. Example: NSDate = 123000 NSTimeInterval = 3600 Added together = 133000 What is the best way to do this? Thanks. ...

String description of NSDate

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

Fuzzy date algorithm

I'm looking for a fuzzy date algorithm. I just started writing one and realised what a tedious taks it is. It quickly degenerated into a lot of horrid code to cope with special cases like the difference between "yesterday", "last week" and "late last month" all of which can (in some cases) refer to the same day but are individually corre...

converting an float to NSDate

I want to convert a float to a NSDate I converted a NSDate into a float using this: // Turn the date into Integers NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendarUnit unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *dateComponents ...

iphone shortdate with 4 digit year

I am sure I am just missing something. But I have googled this for days trying to find how to show a 4 digit year when displaying an NSDate with a style of NSDateFormatterShortStyle. Please let me know if you have a solution. Here is the code I am using now. [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; ...

Odd behavior with timeIntervalSince1970

I'm seeing an odd behavior with trying to get seconds since epoch in objective C. This: NSString *nowTimestamp = [NSString stringWithFormat:@"%d", [[NSDate date] timeIntervalSince1970]]; Outputs 15907296, when the current timestamp should be 1243555623 (05/28/2009 @ 7:08pm EST). The system time on the i...

NSDate and NSDateFormatter - short format date and time in iphone sdk

searched for answers, but the one's i found didn't seem to be ipone specific. I basically need to get current date and time separately, formatted as: 2009-04-26 11:06:54 edit: The code below, from another question on the same topic, generates now: |2009-06-01 23:18:23 +0100| dateString: |Jun 01, 2009 23:18| parsed: ...

NSDate out of scope

Having problems with out of scope for NSDate in an iphone app. I have an interface defined like this: @interface MyObject : NSoObject { NSMutableArray *array; BOOL checkThis; NSDate *nextDue; } Now in the implementation I have this: -(id) init { if( (self=[super init]) ) { checkThis = NO; array = [[NSMut...

NSDate Problem

I have the following code below that is meant to change a class var called "today" forward or backward by one day. It will work one time but then after that it crashes. It will do the same no matter if I press the left button or right button. What am I doing wrong? the var today is a class var initiated as .. today = [NSDate date] Here...

Cocoa - Localized string from NSDate, NSCalendarDate...

I'm using NSDate to get a string such as "18 Jun 09", with code: NSDate *theDate = [NSDate date]; NSString *dateString = [theDate descriptionWithCalendarFormat:@"%d %b %y" timeZone:nil locale: nil]; This works, but only results in an English output. I need the output to be localized in the user's default language. Doe...

How to find what day of the week for any given date using Cocoa

Hi, I'm trying to figure out what day (i.e. Monday, Friday...) of any given date (i.e. Jun 27th, 2009) Thank you. ...

How do I get the current date in Cocoa

I'm getting started developing for the iPhone and as such I am looking at different tutorials online as well as trying some different things out myself. Currently, I'm trying to create a countdown until midnight. To get the number of hour, minutes, and seconds, I do the following (which I found somewhere): NSDate* now = [NSDate date]; ...

How to Check if an NSDate occurs between two other NSDates

I am trying to figure out whether or not the current date falls within a date range using NSDate. For example, you can get the current date/time using NSDate: NSDate rightNow = [NSDate date]; I would then like to use that date to check if it is in the range of 9AM - 5PM. ...

Do an action when a sound has finished playing in AVAudioPlayer?

I am using the AVAudioPlayer framework, and I have several sounds that play one at a time. When a sound is finished playing, I want the application to do something. I tried to use audioPlayerDidFinishPlaying to do the action at the end of the first sound, but I couldn't use that for the second sound because I got a redefinition error. ...

Sort NSArray of date strings or objects

I have an NSArray that contains date strings like this: "Thu, 21 May 09 19:10:09 -0700" I need to sort the NSArray by date. I thought about converting the date string to an NSDate object first, but got stuck there on how to sort by the NSDate object. Thanks. ...