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
9
votes
1 answer

What are the iOS 8.0+ NSCalendarUnits?

I noticed that all the NSCalendarUnits (e.g., NSDayCalendarUnit) is officially deprecated as of iOS 8.0. What is the replacement?
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
9
votes
1 answer

Adding year component to islamic calendar fails

Following code shows the problem: Advancing a full year from the first day of the year 1435 does not result in the first day of 1436. Any ideas what i'm missing? NSDateComponents *components = [[NSDateComponents alloc] init]; [components…
Frank Martin
  • 2,584
  • 2
  • 22
  • 25
8
votes
3 answers

Example for when to use [NSCalendar autoupdatingCurrentCalendar]

I'm looking for an example where + autoupdatingCurrentCalendar would be used instead of + currentCalendar. More specifically where the values based on the calendar are automatically changed when the calendar changes. Do I need bindings for this or…
oliver223
  • 81
  • 1
  • 3
8
votes
0 answers

NSCalendar first day of week and personal settings

In system settings in section "Mail, Contacts, Calendars" user can set any weekday as first day of week. [[NSCalendar currentCalendar] firstWeekday] does not return this value but returns value for current locale. Apple's Calendar app responds to…
Mikhail Grebionkin
  • 3,806
  • 2
  • 17
  • 18
8
votes
3 answers

Checking when a date has passed - Swift

Well, the title pretty much says it all. What I am trying to do is check when a date has passed. So, for example let us say that a user is using my app and then they go to bed and check my app in the morning. When my app opens up I need to check if…
Harish
  • 1,374
  • 17
  • 39
8
votes
3 answers

'DayCalendarUnit was deprecated. Use NSCalendarUnitDay instead' doesn't work

let dateComponents = calendar.components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit, fromDate: date) I got error: 'DayCalendarUnit' was deprecated in iOS version 8.0: Use NSCalendarUnitDay instead But when I replace these names…
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
8
votes
3 answers

Swift - Check if date is in next week / month. ( isDateInNextWeek() isDateInNextMonth() )

We have those convenient functions in calendar: let calendar = NSCalendar.currentCalendar() calendar.isDateInToday(date) calendar.isDateInTomorrow(date) But I am missing those two: …
Yaron Levi
  • 12,535
  • 16
  • 69
  • 118
8
votes
6 answers

Get first day in a month from NSCalendar

I have this subset of a method that needs to get day one of the current month. NSDate *today = [NSDate date]; // returns correctly 28 february 2013 NSCalendar *gregorian = [[NSCalendar alloc]…
bogen
  • 9,954
  • 9
  • 50
  • 89
8
votes
4 answers

Objective-C: Getting the number of days in a calendar year

I am using the following NSCalendar method to get the number of days in a calendar year: NSRange range = [gregorian rangeOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit …
AlexR
  • 5,514
  • 9
  • 75
  • 130
8
votes
2 answers

Changing Gregorian Month and Days names to Islamic? NSDate

I'm trying to display the Islamic current day name , month name. I used NSLocale to set the region to ar_SA, however it's just translating the day and month names from English to Arabic. Output I'm getting in Arabic: ١٢ الأحد ، اكتوبر ، ٢٠١٢ …
Sobiaholic
  • 2,927
  • 9
  • 37
  • 54
7
votes
1 answer

How to save entry to native calendar (Android & iOS ) in react native?

I am looking to save an entry to the native calendar through my app. I have all the entry details such as Name, time/date, location etc . Is there something i can use out of the box in react native. If not are there any existing plugins available…
vijar
  • 733
  • 4
  • 14
  • 23
7
votes
3 answers

Swift - Get date from day of year

We can get day of year for date using below line. let day = cal.ordinalityOfUnit(.Day, inUnit: .Year, forDate: date) But how can we get the date from day of year?
Vijay
  • 791
  • 1
  • 8
  • 23
7
votes
6 answers

Rounding of NSdate to nearest hour in iOS

I have data in the format time: 13:52, 10:30, 11:48 etc I would like to round to the nearest hour. like for 13:52 -> 14:00 , 10:30 -> 11:00 and 11:48 -> 12:00. How can I do that with NSDate?
Sumit Patel
  • 2,547
  • 8
  • 33
  • 45
6
votes
1 answer

What is NSEraCalendarUnit?

I was playing around with NSCalendar and NSDateComponents today and I saw constants like NSDayCalendarUnit and NSEraCalendarUnit. NSDayCalendarUnit returns 4 if today is the 4th of December for instance. NSEraCalendarUnit returns the era which is…
hollow7
  • 1,506
  • 1
  • 12
  • 20
6
votes
2 answers

NSCalendar dateFromComponents: GMT timezone instead of systemTimeZone

This code NSCalendar *calendar =[NSCalendar currentCalendar]; [gregorian setTimeZone:tz]; NSLog(@"%@", [gregorian timeZone]); NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:[NSDate date]]; [comp…
Mitry
  • 375
  • 4
  • 13
1 2
3
40 41