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

NSDateComponents (via MTDates) is returning a strange number for hour (mt_hourOfDay)

I've looked at the related questions with answers, their solutions have not worked. I'm really confused by the output I'm receiving from NSDateComponents and NSDateFormatter (and MTDates for ease of use but I've tried bypassing that to get different…
Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
0
votes
3 answers

Handling Day light time difference

As per our application specification, we need to schedule call for conference, while I scheduling I have been facing problem with Day light time difference. This is the case: US day light time changes on Nov 3 this year, when I schedule a call for…
Newbee
  • 3,231
  • 7
  • 42
  • 74
0
votes
3 answers

Timer won't stop after 45 minutes

I have this NSTimer that I want it to stop after 45 minutes, but it won't stop. What am I doing wrong? TIMER_COUNT = 45 HOURS_IN_HOURS = 60 HOURS_IN_DAY = 24 - (void)start { self.timerCountdown = [NSTimer scheduledTimerWithTimeInterval:1.0…
ytpm
  • 4,962
  • 6
  • 56
  • 113
0
votes
2 answers

NSDateFormatter or NSDateComponents return the same number for different dates

I did build a custom calendar and when I go through the week changing the day number for day, I see strange situation when date is 26, but NSDateFormatter and NSDateComponents return 27, the same is for 27 = 27, you can see a log from. In another…
invoodoo
  • 3,905
  • 1
  • 18
  • 16
0
votes
1 answer

Get first day of the month

I am trying to get an NSDate object from the first day of the current month. I use the following code: NSDateComponents *components = [c components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayOrdinalCalendarUnit |…
the_critic
  • 12,720
  • 19
  • 67
  • 115
0
votes
1 answer

NSPredicate for checking the same date

I want to check to 2 NSDates that they are on the same date (time can be different). What I have currently is this: - (NSPredicate*) predicateWithDate:(NSDate *)date { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents…
Shmidt
  • 16,436
  • 18
  • 88
  • 136
0
votes
1 answer

Formatting NSDates in the same timezone, regardless of the system timezone

I'm importing a number of references dates from a remote source. The dates represent times of day on an arbitrary day of the year (in this case 01/01/2000). They are supplied in as Unix timestamps. For example 946717200 represents 9am. I'm also…
Jonathan
  • 1,592
  • 1
  • 14
  • 28
0
votes
1 answer

Possible bug in NSDateCompononents?

I was simply playing around with timers and i found this: - (void)viewDidLoad{ [super viewDidLoad]; NSDate *date = [NSDate date]; dFormatter = [[NSDateFormatter alloc] init]; //instance variable NSCalendar *calendar =…
ragnarok
  • 75
  • 1
  • 7
0
votes
0 answers

Unrecognized Selector Error using components:fromDate:toDate:options

+(int)weeksBetween:(NSDate *)startDate and:(NSDate *)endDate { NSInteger days = [[[NSCalendar currentCalendar] components: NSDayCalendarUnit fromDate: startDate toDate: endDate options: 0] day]; return (days)/7; } I have tried…
Kevin
  • 3
  • 1
0
votes
1 answer

How to compare NSDate objects efficiently

I have to compare many managed objects and group them by date. I can't use NSDateComponents because it's too slow to compare two NSDate objects. How can I compare them in a more efficient way, so that I can save processing time?
ashvardanian
  • 424
  • 1
  • 6
  • 17
0
votes
3 answers

Add 3 Hours to an NSDate's Hour

I want to add 3 hours to my current date. I am using the following code to add hours but it adds 6 hours to the current date. NSDate *n = [NSDate date]; int daysToAdd = 3; // or 60 :-) // set up date components NSDateComponents *components1 =…
Rushabh
  • 3,208
  • 5
  • 28
  • 51
0
votes
0 answers

Different dates as result when converting from NSDateComponents to NSDate

I am experimenting with NSDate and NSDateComponents and have a code: ... NSDateComponents *newComponents = [[NSDateComponents alloc] init]; [newComponents setYear:from_year]; [newComponents setMonth:from_month]; …
Alex Thumb
  • 45
  • 6
0
votes
2 answers

Creating Custom NSString from NSDate

I need a NSString with the format "yyyy-mm-dd - 11:00:00" Year, month, and date should be from the current date, while hour, minute, and second should be 11,00,00. I could not figure how to do that.
yabtzey
  • 391
  • 1
  • 7
  • 17
0
votes
1 answer

NSDateComponents weekOfMonth does not alter weekOfYear

Contrary to what I expected setting the weekOfMonth property from an NSDateComponents object does not have an effect on weekOfYear... NSDateComponents *iterativeComponents = [calendar components: NSYearCalendarUnit| …
ff10
  • 3,046
  • 1
  • 32
  • 55
0
votes
3 answers

Get the difference between dates like Facebook comments on iOS

I want to get the difference between two dates which are being received in dot net format. I have converted the date into an NSDate. But I am not able to get the exact difference (the hours, minutes, and seconds fields are zero) between the dates. I…
arunit21
  • 670
  • 1
  • 11
  • 25