Questions tagged [nscalendar]

NSCalendar is an Apple MacOS and iOS class to deal with calendrical computation.

a “toll-free bridged” counterpart to CFCalendar, an Objective-C component that provides information about the calendar and support for computations such as determining the range of a given calendrical unit and adding units to a given absolute time.

Reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html

612 questions
5
votes
2 answers

Why NSCalendar's dateFromComponents returns wrong date?

I am expecting 2010-10-11 00:00:00 But instead I receive 2010-10-10 21:00:00 +0000 I know, that I can add a few hours and receive desired date, but I do not understand why I get previous day with 21 hours... Please, help! NSDateComponents *comps =…
arthur_skypro
  • 97
  • 3
  • 8
5
votes
0 answers

iPhone restarted when I add multiple local notification more than 1000

In my calendar based app , I create the local notification for all event from my app also. On every launch I remove all notification and create for 2 years. so, its above 1000 event is there. When local notification creation device memory goes to 80…
Ammaiappan
  • 539
  • 3
  • 22
5
votes
1 answer

NSCalendar does not correct for GMT time

When I compute the start of a day, a time difference of one hour is obtained. Why is not corrected for GMT+1? let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! cal.timeZone = NSTimeZone.localTimeZone() let startOfToday =…
Gerard
  • 349
  • 2
  • 16
5
votes
1 answer

Convert currentCalendar() Date to NSCalendarIdentifierChinese

I have written the function to get the 1st day of the year on the Chinese calendar for the past 100 years. Some of the values which are returned from the loop are correct. i have verified the Chinese new year dates with this link…
5
votes
1 answer

Apple Swift: how to get current seconds in 1/100 or 1/1000?

func updateTime() { var date = NSDate() var calendar = NSCalendar.currentCalendar() var components = calendar.components(.CalendarUnitSecond, fromDate: date) var hour = components.hour var minutes = components.minute var…
stnbrk
  • 119
  • 3
  • 12
5
votes
2 answers

NSCalendar in Swift - init can return nil, but isn't optional

NSCalendar(calendarIdentifier: calendarName) can return nil if calendarName is not valid - this is the original Objective-C behaviour, and is also true in Swift. However, it appears that the compiler believes the initializer returns an NSCalendar…
Grimxn
  • 22,115
  • 10
  • 72
  • 85
5
votes
1 answer

NSCalendarUnit flag to set all flags

The following will create an NSDateComponents object containing day and weekday but not hour: var today = NSDate() var gregorian = NSCalendar(calendarIdentifier: NSGregorianCalendar) var flags: NSCalendarUnit = .DayCalendarUnit |…
Chris Redford
  • 16,982
  • 21
  • 89
  • 109
5
votes
1 answer

NSCalendar: Problem getting weeks in a month

I am creating a calendar control of sorts... One thing I need to know is how many weeks are there in a Month... So NSCalendar rangeOfUnit:inUnit:forDate Seems to be exactly what I need... Except I am noticing something that seems off and I can't…
Stanley.Goldman
  • 4,317
  • 2
  • 23
  • 25
5
votes
2 answers

Display week & day lists for everymonth when we pass the year

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"yyyy"; NSDate *date = [dateFormatter dateFromString:@"2011"]; NSCalendar *calendar = [[NSCalendar…
sadeesh
  • 343
  • 1
  • 8
5
votes
2 answers

Using setDoesRelativeDateFormatting: YES and setDateFormat: with NSDateFormatter

NSDateFormatter has a lovely support for producing relative dates such as "Today", "Tomorrow", "Yesterday" when these are supported by the current language. A great advantage is that all of these are localised for you already – you don't need to…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
5
votes
1 answer

Calendar API - iOS7

Is there any calendar API for iPad? Please refer to image. This is calendar application in iOS7
Taimur Ajmal
  • 2,778
  • 6
  • 39
  • 57
5
votes
3 answers

In Objective-C, to get the current hour and minute as integers, we need to use NSDateComponents and NSCalendar?

I'd like to get the current hour and minute as integers. So if right now is 3:16am, I'd like to get the two integers: 3 and 16. But it looks like [NSDate date] will give the number of seconds since 1970, or it can give a string of the current time…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
4
votes
0 answers

Getting first date in week given a year and weeknumber

I'm trying to get the first date in a week giving a year and weeknumber in objective-c. I want to take the dutch calendar into account. Monday is the first day in the week here. So just as it is in MS Outlook I would like my function to return…
4
votes
2 answers

Do I understand NSHebrewCalendar correctly?

I conducted a quick test with the Cocoa Touch to see how NSHebrewCalendar works. I'm particularly interested in the month numbers. I used a date picker to easily change dates, and I passed it in to a method which logs the hebrew date, the hebrew…
Moshe
  • 57,511
  • 78
  • 272
  • 425
4
votes
1 answer

Why do Swift's Date time intervals ignore leap seconds?

30 June 2012 had a leap second. As such it lasted 86401 seconds. However, in the following Swift code, timeInterval is 86400. How come? let formatter = ISO8601DateFormatter() let date = formatter.date(from: "2012-06-30T00:00:00Z")! let dayAfter =…
Mick F
  • 7,312
  • 6
  • 51
  • 98