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
6
votes
3 answers

Swift 4 : Set Different Date and Time

I know how to get local date and time, but what I want to do is getting the date and time from different places. For example, I want to find out what the time and date is in New York. How can i solve this simple problem? Here is my code for local…
jorjj
  • 1,479
  • 4
  • 20
  • 36
6
votes
2 answers

Calculate business days and weekend days between 2 NSDates

I'm trying to calculate the amount of workdays + business days between 2 NSDates but I can't seem to find a proper solution. I can currently find the amount of Days between 2 NSDates like so: func reloadData(){ let cal =…
Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67
6
votes
2 answers

Getting the first date of current quarter

I'm trying to get the first and the last date of current quarter, i'm using it: NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitQuarter | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear…
daleijn
  • 718
  • 13
  • 22
6
votes
2 answers

Detect if two dates are within the same calendar day

My app presenting a list of messages, each has a creation date. I don't want to just show the date but to show different formats according to how much time passed from the creation date. for example, this is how I create the date string from the…
Mario
  • 2,431
  • 6
  • 27
  • 34
6
votes
3 answers

NSCalendar, why does setting the firstWeekday doesn't effect calculation outcome?

i need to calculate the weekday for a given date, however, depending on the calendar a week can star on Monday and somwhere on Sunday so i wanted to set it, to start on Monday, using [[NSCalendar currentCalendar] setFirstWeekday:2]; however, the…
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
6
votes
2 answers

Storing an absolute NSDate, not relative to a timezone

I am creating an iOS app to track attendance. Each attendance entry is stored in an object which has a status attribute (e.g. present, absent) and an NSDate attribute called date which denotes the day which that attendance record was taken. When I…
Skoota
  • 5,280
  • 9
  • 52
  • 75
6
votes
2 answers

I want to get a quarter value in NSDateComponents class

I want to get a quarter value from specified date. (*date variable) So. I have made following code and run. but, quarter value is zero. Why quarter value is zero? where's problem? Please advice from advanced man. NSDateComponents *comp1 =…
S.J. Lim
  • 3,095
  • 3
  • 37
  • 55
5
votes
1 answer

NSDateFormatter: week of year and first weekday

I would like to get a NSString from a date, with a date format like this: MMEEEY ww The problem is for the 'ww', the week of year. I have to compare this format with another, taken from a backoffice. But the first weekday of the backoffice is…
syfonseq
  • 123
  • 1
  • 6
5
votes
2 answers

[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance

I would like to compare difference between two dates, but with the code below I got the error "[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance." What's wrong with the code? NSDate *dateAdded=[eventDictionary…
Nimit Pattanasri
  • 1,602
  • 1
  • 26
  • 37
5
votes
3 answers

Calculating the end of a month, or its last second

I have the simplest of tasks that I can't figure out how to do correctly. With the snippet below I can find out the beginning of a month. NSCalendar *cal = [NSCalendar currentCalendar]; NSDate *beginning = nil; [cal rangeOfUnit:NSMonthCalendarUnit…
epologee
  • 11,229
  • 11
  • 68
  • 104
5
votes
2 answers

Is the starting day of the week stored in NSLocale somewhere?

I live in the Netherlands. We Dutch people like to see Monday as the start of the week. I know that people in the US like to consider Sunday as the start of the week. Silly Americans ;) If I want to present a week view to my global users, can I get…
epologee
  • 11,229
  • 11
  • 68
  • 104
5
votes
1 answer

Retrieving 1st day of month using NSCalendar

I execute following snippet of code: NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)…
Sam
  • 902
  • 8
  • 16
5
votes
2 answers

Objective-C midpoint between two times

I have two NSDates formatted as "h:mm a" as time, (i.e. 6:00 AM and 8:00 PM). I am trying to find out what time is the midpoint between those two times. For the example above, the midpoint between 6:00 AM and 8:00 PM would be 1:00 PM. But I do not…
OscarTheGrouch
  • 2,374
  • 4
  • 28
  • 39
5
votes
3 answers

How to programmatically build NSArray of localized calendar month names?

I am in the process of localizing/internationalizing my iPhone app and have a question. In one place in my app, I show a list of the 12 months of the year. As it is in its currently non-localized state, I simply have the months January - December…
Jason
  • 14,517
  • 25
  • 92
  • 153
5
votes
5 answers

NSDate - one year ago, dilemma

I'm trying to do something that, for me, is a bit difficult. But I'm sure someone has some insight. Given a date, say January 17, 2011, I'm trying to figure out the day that corresponds to this date one year ago. So January 17, 2011 is a Monday, and…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317