Questions tagged [nsdatecomponent]

NSDateComponents encapsulates the components of a date in an extendable, object-oriented manner. This is available in Apple's Foundation Framework .It is Available in iOS 2.0 and later and for OSX v10.4 and later. The issues related with date components in apple's Cocoa and cocoa touch can be tagged with NSDateComponent tag

NSDateComponents serves an important role in Foundation’s date and time APIs. By itself, it’s nothing impressive—just a container for information about a date (its month, year, day of month, week of year, or whether that month is a leap month).

NSDateComponents can be initialized and manipulated manually, but most often, they’re extracted from a specified date, using NSCalendar -components:fromDate::

An NSDateComponents object is not required to define all the component fields. When a new instance of NSDateComponents is created the date components are set to NSUndefinedDateComponent.

Source:

Sample :

 NSCalendar *calendar = [NSCalendar currentCalendar];
 NSDate *date = [NSDate date];

 NSDateComponents *components = [[NSDateComponents alloc] init];
 [components setWeekOfYear:1];
 [components setHour:12];
 NSLog(@"1 week and twelve hours from now: %@", [calendar dateByAddingComponents:components toDate:date options:0]);
15 questions
12
votes
2 answers

NSDateComponents - day method returning wrong day

I can't seem to figure out why the day doesn't change when I get to the 6th of November, 2011. All I'm doing is iterating through the days. Any help would be appreciated. Here is my code: NSCalendar* calendar = [[NSCalendar alloc]…
Matt W.
  • 956
  • 9
  • 21
8
votes
6 answers

How to set time on NSDate?

I want to set the NSDate time with my desired hours:minutes:seconds currently im working with NSDate component but it is not giving the desired result [comps setHour: -hours]; [comps setMinute:0]; [comps setSecond:0]; NSDate *minDate = [calendar_c…
2
votes
1 answer

UILocalNotification set repeatCalendar

I am New to NSCalander, NSdates, and NSDateComponents Basically I have a Local Notification and I want to repeat the fire date based on the selection of the user, let's say on Sunday and Monday only. We should use repeatCalendar property for the…
Atef
  • 2,872
  • 1
  • 36
  • 32
1
vote
2 answers

NSDateComponents returns week 53 on 1/1/1970

So when extracting the dates components from NSDate object using NSCalendar and NSDateComponents I encountered a weird behavior. If the date is 0 sec from 1970 the week component will return 53. Is there an explination for this or a way to fix other…
Edward Ashak
  • 2,411
  • 2
  • 23
  • 38
0
votes
1 answer

Regarding NSDateComponents TimeZone

I have to set an UIAlertNotification at 6:00 pm local time. The time is set at 11:00am and will get to 18:00 pm because the local time zone I am in right now is GMT+6:00. However, it will be different in different time zones. I want it to be 6:00pm…
Ahsan
  • 2,964
  • 11
  • 53
  • 96
0
votes
1 answer

Why NSCalendar date differ from NSDateComponents components date?

ANy idea why this code output "2011-11-30 23:00:00 +0000" instead "2011-12-01 00:00:00 +0000" NSDateComponents *minDateComponents = [[NSDateComponents alloc] init]; [minDateComponents setYear:2011]; [minDateComponents…
Marcin
  • 3,694
  • 5
  • 32
  • 52
0
votes
1 answer

NSDate Math? Now and Fire timer in the future

I have been racking my brains on this one looking for a quick solution. I need to fire off a NSTime at a specific time based on the current time in a specific time zone. For example, I get the current time in PST: NSDate *now = [NSDate…
rsirota
  • 321
  • 3
  • 15
0
votes
1 answer

why does this code display the date being SAT where with NSDateComponent setWeekday I used 1 for SUN?

Why does this code display the date being SAT where with NSDateComponent & setWeekday I used 1 for SUN? // Set Day NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setWeekday:1]; [comps setHour:13]; [comps setMinute:30]; NSCalendar…
Greg
  • 34,042
  • 79
  • 253
  • 454
0
votes
1 answer

NSDate.timeIntervalSinceDate without day time saving adjustments?

When I compare the beginning to the end of the day of october 25, I get 89999 seconds (25 hours). I compare the dates using the following method: endOfDay.timeIntervalSinceDate(startOfDay) However, when I compare the hours, I get 24. I use the…
the Reverend
  • 12,305
  • 10
  • 66
  • 121
0
votes
2 answers

ios8 - seeing if a record is past or future

I'm parsing an array and want to weed out records from before now. I've got this code: int i = 0; for (i=0; i < tempArray.count; i++) { currentObjectArray = tempArray[i]; NSString *dateString = [currentObjectArray…
ICL1901
  • 7,632
  • 14
  • 90
  • 138
0
votes
1 answer

iOS- Getting months and year over 2 yrs period

I'm new to iOS and i'm having a hard time getting months and years for a period of 2 yrs. i'm putting them into an NSArray. All I can get is one year, but beyond that, the years don't increment to reflect year change. Please help? Thanks NSDate …
0
votes
2 answers

Schedule UILocalNotifications for a particular week of a month

I am scheduling UILocalNotifications in my project. At present I am scheduling the notification for the daily basis. Now the client has asked to do particular scenarios like scheduling for every second week. Is there a way to do this? Please can any…
Nassif
  • 1,113
  • 2
  • 14
  • 34
-1
votes
1 answer

I am getting the time format like 07:14 Am/Pm that I required to convert like 19:14 in NSDateComponent

I want to get localnotification when I set time so In the timepickker i am getting the time format like 07:14 Am/Pm that I required to convert like 19:14 so that I can set the values like I want to convert 07 to 19 how to do that to put the values…
VyTcdc
  • 986
  • 10
  • 32
-1
votes
1 answer

Change NSDate to Friday of that Week

Currently I have the below code to increment my days to the next friday, however what I need is to get the friday of the current week. For example if it is last Sunday, 03/01. I would expect my response to be last Friday(02/28) not Friday(03/06). …
bmjohns
  • 6,344
  • 1
  • 33
  • 39
-1
votes
2 answers

NSPredicate: unrecognized selector sent to instance when filtering array of NSDateComponents using filteredArrayUsingPredicate

I have some code in which I'm getting an array of dates from now to one year NSCalendar* calendar = [NSCalendar currentCalendar]; NSMutableArray *dateComponentsInRange = [NSMutableArray new]; NSDate *curDate = [dates…
Black Sheep
  • 1,665
  • 1
  • 22
  • 32