nsdate

NSDate / NSDateComponent problem

Hello, Let's say we are the 15/07/2010, I would like to get the first day of the previous week, which is the 5 of July. I have the following method but it does not work. Seems that I have a problem with the weekday attribute... + (NSDate *)getFirstDayOfPreviousWeek { // Get current date NSCalendar *cal = [[NSCalendar alloc] initWithCal...

iPhone- Dynamically update NSDate for clock?

I've made a clock, and I'm trying to update it so it displays, well, the time. When I initiate the NSDate it is an instance of the exact current time, for the time it was initiated. So what I have going on here is pinging the updateTime function with an NSTimer to update the clock every 3 seconds. It seems that there should be a way to ...

How to create a custom date on iPhone

I'm trying to set some components of todays date with NSDateComponent like so: NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:1]; [comps setHour:1]; [comps setMinute:44]; NSCalendar *cal = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDate *date = [...

Error when releasing NSdate from [NSDateComponents components: fromDate: toDate: options:]

Okay so i got this clas called event. It has a property called eventDate wich is a NSDate. I made a method to return how many years it is since the event date: - (double)yearsSinceEvent { double years; // Get the system calendar NSCalendar *sysCalendar = [NSCalendar currentCalendar]; // Create the NSDates NSDate *...

Timezone/DST agnostic timestamps with NSDate

I'm creating objects which will be sent to a server, and I'm trying to ensure I account for timezone and Daylight Savings issues, so I want my timestamps to be "seconds since 1970" regardless of timezone, etc. Is [NSDate timeintervalSinceReferenceDate] sufficient for this? In the docs I know it says time since January 1 1970 00:00:00 GM...

Create new NSDate object from the date returned from UIDatePicker

How to create new NSDate object from [myUIDatePicker date] ? ...

iPhone Objective-C convert String to NSDate *special case

Hey everyone, I know this kind of questions have been asked a thousand times on this forum, but I have a slightly special case which I could really use some help with. I have an NSString *expirationDate with the value = "2010-06-23 04:28:59.341818" I need to convert to an NSDate object and compare against the current Date/Time. Can so...

NSDate Question

How do I create a NSDate of August 1, 2005? Found NSDateComponent on the internet, but seems too complicated. ...

Convert NSDate to NSString

I have the following: NSDateFormatter* df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate* date = [df dateFromString:[sDate stringByReplacingOccurrencesOfString:@"Z" withString:@"-0000"]]; [df release]; I would like the output string to be "9/20/10" How can I do this? ...

Simplest way to loop between two NSDates on iPhone?

What's the simplest way to loop from one date to another? What I want conceptually is something like this: for (NSDate *date = [[startDate copy] autorelease]; [date compare: endDate] < 0; date = [date dateByAddingDays: 1]) { // do stuff here } This doesn't work, of course: there's no dateByAddingDays:. And even if it did, it...

NSDateFormatter problem

hey i have my date as "7/30/2010". How do i print it as only the Month and Date ie. "7/30" I tried using NSFormatter but it prints my current date and not which is present in my database. ...

Get Date Parts from a NSDate value

Hello, I'm using a UIDatePicker and I'm having problems with converting this data to a System.DateTime value in MonoTouch. There are problems with conversions from NSDate to DateTime, which I've mostly solved, but now I see that if you choose a date that is NOT in the same Daylight Savings Time period then you are an hour off. For exa...

NSDate formatting using locale

Hi All, I was using the following method for creating NSDate Object based on the timezone and locale. descriptionWithCalendarFormat:timeZone:locale: [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timezone:nil locale:nil]; But this method is no mo...

NSDate dateFromString deprecated?

I'm trying to use the NSDate dateFromString method but I'm getting an warning and it's crashing the app. The code looks like: NSString *pickerDate = [NSString stringWithFormat:@"%@", timeSelector.date]; NSDate *defaultDate = [NSDate dateFromString:pickerDate]; The warning is: 'NSDate' may not respond to '+dateFromString'. It appear...

A problem when converting string to date in iPhone?

How to convert NSString 2010-08-03 04:37:31.0 to August 3, 2010? Is it possible? ...

Compare NSDate objects only in terms of year month day

If I want to use the compare method to compare two days: [day1 compare:day2] == NSOrderedAscending How to compare only by year-month-day? ...

NSDate MPMediaItemPropertyReleaseDate always returns 1801

I'm trying to extract the year from MPMediaItemPropertyReleaseDate in an MP3 file using iOS SDK 4.0 but it seems to always return Jan 1 1801 for the date. Does anyone know how to properly extract that from the returned NSDate? Here's what I'm doing: NSString *locale = [[NSLocale currentLocale] localeIdentifier]; NSLog([[mediaItem value...

How to set the NSDate on iPhone?

Hi, everyone, I want to ask 2 questions about the NSDate of iPhone application. 1) How to set the NSDate *startDay to 01-01-2010 and NSDate *endDay to 31-12-2010 2) how many day between the startDay and the endDay. What should I do? Thank you very much. ...

How can I create a complete NSDate object that represents the next specified day time?

I probably didn't word that title clearly enough, but if the user specifies a time of 2:30pm and it's currently 2:00pm, then I need an NSDate object that represents the current day with a time of 2:30pm. If the user specifies a time of 2:30pm and it's currently 3:00pm, then I need an NSDate object that represents tomorrow with a time of...

NSDateFormatter parsing date incorrectly

I'm extracting strings from a text that represent dates. They look like this: Monday August 16, 2010 05:28 AM EST I'm trying to parse them with a NSDateFormatter. I've set its format to: [dateFormatter setDateFormat:@"EEEE MMMM d, YYYY h:mm a z"]; However, this doesn't work. For the example I gave above, if I convert the string to a ...