nsdate

How does one subtract hours from an NSDate?

I would like to subtract 4 hours from a date. I read the date string into an NSDate object use the following code: NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate * mydate = [dateFormatter dateFromString:[dict objectForKey:@"published"]]; W...

warning no-method descriptionWithCalendarFormat:timeZone:locale found

I am getting this warning in xcode 3.1.3 iphone os 3.0. This method is also not available in the NSDate class. But I am getting the date from this method. Can anyone please tell me How can I get rid of this warning???? ...

Objective-C timespan

In C#, if I wanted to parse out a string into a date and timespan, I'd do something similar to the following: String input = "08:00"; DateTime time; if (!DateTime.TryParse(input, out time)) { // invalid input return; } TimeSpan timeSpan = new TimeSpan(time.Hour, time.Minute, time.Second); My Google-Fu has been less than desir...

How to store dates without times in Core Data

I've been trying to find a sensible way of storing daily data using Core Data on the iPhone. My app receives data in csv format, with a date but no time: date, cycles 2009-08-01, 123 2009-08-02, 234 2009-08-03, 345 2009-08-04, 456 When this data is stored, there should only be one record per day. I figured the best thing to do was cr...

NSDate init question, related to memory management in Objective-C

I have an NSDate object created by NSDate *date = [[NSDate alloc] init]; Later, I want to reset the date to the "now", so I thought that [date init]; or date = [date init]; might do the job, but they don't. Instead, [date release]; date = [[NSDate alloc] init]; works. I'm a bit confused about this, since in the documentation ...

How to Convert XML Date format to Cocoa

I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @"MMM dd, HH:mm a" I retrieve the xml format in an NSString. I tried to use the NSDateformatter: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"MMM dd, HH:mm a"]; any ideas? ...

Nil NSDate when trying to get date from UTC string in zulu time

Writing an iPhone app in Objective-C, I have a date in string form (in UTC format, with a Z on the end to denote zero UTC offset, or zulu time), which I need to parse into an NSDate object. A bit of code: NSDateFormatter* df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"]; NSString* str = @"2009-08-11T06...

Does anyone know how to convert NSDate to Date(ticks)?

Does anyone know how to convert a NSDate to JSON Date(ticks) to have sent to a .net web service? ...

Convert UTC NSDate to local Timezone Objective-C

Does anyone know how to convert a UTC NSDate to local timezone NSDate in Objective C? ...

Ordinal Month-day Suffix Option for NSDateFormatter setDateFormat

What setDateFormat option for NSDateFormatter do I use to get a month-day's ordinal suffix? e.g. the snippet below currently produces: 3:11 PM Saturday August 15 What must I change to get: 3:11 PM Saturday August 15**th** NSDate *date = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [date...

SQLite: Need Date >= (x) number of days from today

Trying to select a date (x) days from today's date, where the date would be start of day (e.g. 12:00am that day). For example, a query with date 5 days earlier.. @"select pkey, dateofmod from data WHERE dateofmod >= date('now', '? days')" , [NSNumber numberWithInt:-5]; doesn't seem to work. (using FMDB). ...

Countdown Timer in Cocoa

Hi Everyone: I am wondering if there is some way that I can create a timer that countdown from a given time. For example, say I want this timer to last an hour. There will be a NSTextField that will show the time remaining (ex. 25 minutes), and will auto update every minute to the new value. And then, when an hour is finally passed, ...

Trouble with Core Data dates...

I've got a Core Data model set up, with two entities in a one-to-many relationship (Items, and for each item, there can be multiple ResetDates). I'm pretty confident the model is set up correctly. I can add new Items, and when doing so, add a new ResetDate (using the current date, with [NSDate date]). I can retrieve and display Items. W...

How can I generate convenient date ranges based on a given NSDate?

I'm creating a report generator in Cocoa, and I need to produce convenient date ranges such as "Today", "This Week", "This Month", "This Year", etc. Is there a good way to do this? Here is my skeleton thus far: @interface DateRange : NSObject { NSDate startDate; NSDate endDate; } @property (assign) NSDate * startDate; @propert...

NSDate -dateWithNaturalLanguageString: on iPhone?

In the iPhone docset for NSDate, in the discussion area they discuss -dateWithNaturalLanguageString:locale:, however they don't document the method elsewhere on the page. I've used the method before for iPhone and it worked just fine, although I got warnings. Now that I'm building with -Werror (which I should have been doing all along ^...

[NSDate description] -> NSDate

Hi, I store my NSDates to a file in the international format you get when you call description on a NSDate. However, I don't know how to go back: from the string-format to a NSDate object. NSDateFormatter seems to be limited to a couple of formats not including the international one. How should I go back from the string-format? Thank...

Is it possible to create an own calendar system in cocoa touch / UIKit?

There are some constants for NSLocale, like NSJapaneseCalendar, but what if I wanted to create a "Physical Calendar" or something that isn't there? Is there a way to define an arbitrary calendar system and then use that with NSDate, NSDateComponents and NSCalendar? ...

NSString to NSDate

I got a string that contains the current date by using this : NSString *date = [[NSDate date] description]; At a different point I am want to retrieve the date from this string and I use the following code [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *dateFormatter = [[NSDateFormatter...

creating a timer when firing a function

Hello all , I'd like to create some sort of timer that will take the time between firing different kind of functions but I'm having no such luck so far. I assumed I should use the NSDate object and I've done this so far. I've created several functions -(void)startTime:(id)sender { starttime = [NSDate date]; **[starttime re...

How to Get time difference in iPhone.

I have 2 arrays with time values in it. They are in the following format. mm:ss:hundreds of a sec. I want to get the difference between the two [lastObjects] in the arrays. NSDate is not working because the last value is in hundredsth of a sec. A question. If the second date is larger than the first will it give me a negative numb...