Questions tagged [nsdatecomponents]

NSDateComponents is a class in Apple's Cocoa and CocoaTouch frameworks which represents either a date or a period of time as composed of several elements -- days, hours, and months, for example.

NSDateComponents encapsulates the components of a date in an extendable, object-oriented manner.

Resources:

567 questions
0
votes
1 answer

Date difference: currentCalendar vs. gregorianCalendar

NSDateComponents *components; components = [[NSCalendar currentCalendar] components: NSDayCalendarUnit fromDate: startDate toDate: endDate options: 0]; days…
Fabrizio
  • 183
  • 1
  • 12
0
votes
1 answer

components:NSQuarterCalendarUnit gives the total quarters between 2 dates?

NSDateComponents *result = [[NSCalendar currentCalendar] components:NSQuarterCalendarUnit fromDate:start toDate:end options:0]; NSInteger numberOfQuaters = [result quarter]; why this code will return always 0 ? That shouldn't give me…
Fabrizio
  • 183
  • 1
  • 12
0
votes
2 answers

How many quarters between two dates?

NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *dateStart = [calendar components:unitFlags…
Fabrizio
  • 183
  • 1
  • 12
0
votes
1 answer

How to store NSDate plus 7 calendar days?

I need to be able to store the current NS Date plus 7 days. I already store the current NSDate. I then want to compare the two dates, to get the number of days difference between the two and display within a label. The idea is to count down from 7…
mreynol
  • 309
  • 3
  • 17
0
votes
2 answers

How do I implement previous/next month buttons and show dates for current month?

Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I…
0
votes
2 answers

Display NSDates in terms of week

Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I…
Angad Manchanda
  • 183
  • 5
  • 17
0
votes
1 answer

NSCalendar to get date difference between now and end of year gives a zero month

I'm getting a 0 for the month when I try to get the date difference from now and the end of the year. I'm using a NSCalendar object to get the difference between two NSDate objects. NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps…
Ted pottel
  • 6,869
  • 21
  • 75
  • 134
0
votes
2 answers

iPhone Is there a way to get a nsdate from a NSDateComponents

I'm trying to figure out how to create a NSDate that is set to the end of the year. ie 2013, I found a method that you can get the time since 1970 by adding the amount of seconds. I don't see this working because cal the seconds would have to take…
Ted pottel
  • 6,869
  • 21
  • 75
  • 134
0
votes
1 answer

Using NSDateComponents to test date equality when times differ

I want to test if two NSDate objects have the same year/month/day but different times of day. Here is my code: NSDate *date1 = [dataDictionary1 valueForKey:@"date"]; NSCalendar *calendar = [[NSCalendar alloc]…
kiks
  • 105
  • 1
  • 7
0
votes
1 answer

Determine iDevice current date in Xcode - NSDate

I want to create a simple if function which carries out a bit of code depending on if the current iDevice year is 2012. I have tried to use NSCalendar and NSDateComponents in Xcode for this but have failed... :( Anyone know of any good resources or…
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
0
votes
1 answer

NSDateComponents on IOS6 not working?

I have a simple program which was working with IOS4 and 5. Now with IOS 6 I'm getting the following error message: 2012-10-05 11:08:16.386 app[1698:19d03] 2012-10-05 09:08:11 +0000 2012-10-05 11:08:18.072 app[1698:19d03] 2012-10-05 09:08:11…
0
votes
2 answers

Get Month and year of 1 year advance in iPhone

in my app I need to get month name and year for next 1 year and store in array. I mean to say suppose today's September 2012, I need month name and year till August 2013. Can you please tell me how will I get month and year? Thanx in advance
iCoder4777
  • 1,682
  • 1
  • 14
  • 35
0
votes
2 answers

Converting String to Date to String with funky error! (Only when running on device)

I'm getting the weirdest error when I run this on my device (but not on simulator): I am getting a date from a JSON object, like this: NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"EEE MMM d HH:mm:ss Z yyyy"]; NSDate…
Sti
  • 8,275
  • 9
  • 62
  • 124
0
votes
1 answer

NSDate early by 1 hour?

I am using the following code to set a date object: NSDate *date = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents *components = [gregorian components:…
Jack Nutkins
  • 1,555
  • 5
  • 36
  • 71
0
votes
1 answer

Not removing the Time Components from NSDate

I need to remove the time components from NSDate for instance: I have the value of '2012-08-12 22:15:54 +00000' but I got the value '2012-08-12 03:00:00 +00000' The Code I am Using is: NSDate* getNDateOfWeek(int week, int day) { NSDate *now =…
Agus
  • 1,604
  • 2
  • 23
  • 48