Class: NSCalendar
Overview
Calendars encapsulate information about systems of reckoning time in which the beginning, length, and divisions of a year are defined. They provide information about the calendar and support for calendrical computations such as determining the range of a given calendrical unit and adding units to a given absolute time.
Class Method Summary (collapse)
-
+ autoupdatingCurrentCalendar
Returns the current logical calendar for the current user.
-
+ currentCalendar
Returns the logical calendar for the current user.
Instance Method Summary (collapse)
-
- calendarIdentifier
Returns the identifier for the receiver.
-
- components:fromDate:
Returns a NSDateComponents object containing a given date decomposed into specified components.
-
- components:fromDate:toDate:options:
Returns, as an NSDateComponents object using specified components, the difference between two supplied dates.
-
- dateByAddingComponents:toDate:options:
Returns a new NSDate object representing the absolute time calculated by adding given components to a given date.
-
- dateFromComponents:
Returns a new NSDate object representing the absolute time calculated from given components.
-
- firstWeekday
Returns the index of the first weekday of the receiver.
-
- initWithCalendarIdentifier:
Initializes a newly-allocated NSCalendar object for the calendar specified by a given identifier.
-
- locale
Returns the locale for the receiver.
-
- maximumRangeOfUnit:
The maximum range limits of the values that a given unit can take on in the receive As an example, in the Gregorian calendar the maximum range of values for the Day unit is 1-31.
-
- minimumDaysInFirstWeek
Returns the minimum number of days in the first week of the receiver.
-
- minimumRangeOfUnit:
Returns the minimum range limits of the values that a given unit can take on in the receiver.
-
- ordinalityOfUnit:inUnit:forDate:
Returns, for a given absolute time, the ordinal number of a smaller calendar unit (such as a day) within a specified larger calendar unit (such as a week).
-
- rangeOfUnit:inUnit:forDate:
Returns the range of absolute time values that a smaller calendar unit (such as a day) can take on in a larger calendar unit (such as a month) that includes a specified absolute time.
-
- rangeOfUnit:startDate:interval:forDate:
Returns by reference the starting time and duration of a given calendar unit that contains a given date.
-
- setFirstWeekday:
Sets the index of the first weekday for the receiver.
-
- setLocale:
Sets the locale for the receiver.
-
- setMinimumDaysInFirstWeek:
Sets the minimum number of days in the first week of the receiver.
-
- setTimeZone:
Sets the time zone for the receiver.
-
- timeZone
Returns the time zone for the receiver.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) autoupdatingCurrentCalendar
Returns the current logical calendar for the current user. Settings you get from this calendar do change as the user’s settings change (contrast with currentCalendar).Note that if you cache values based on the calendar or related information those caches will of course not be automatically updated by the updating of the calendar object.
+ (Object) currentCalendar
Returns the logical calendar for the current user. The returned calendar is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences. Settings you get from this calendar do not change as System Preferences are changed, so that your operations are consistent (contrast with autoupdatingCurrentCalendar).
Instance Method Details
- (String) calendarIdentifier
Returns the identifier for the receiver.
- (NSDateComponents) components(unitFlags, fromDate:date)
Returns a NSDateComponents object containing a given date decomposed into specified components. The Weekday ordinality, when requested, refers to the next larger (than Week) of the requested units. Some computations can take a relatively long time.The following example shows how to use this method to determine the current year, month, and day, using an existing calendar (gregorian):
- (NSDateComponents) components(unitFlags, fromDate:startingDate, toDate:resultDate, options:opts)
Returns, as an NSDateComponents object using specified components, the difference between two supplied dates. The result is lossy if there is not a small enough unit requested to hold the full precision of the difference. Some operations can be ambiguous, and the behavior of the computation is calendar-specific, but generally larger components will be computed before smaller components; for example, in the Gregorian calendar a result might be 1 month and 5 days instead of, for example, 0 months and 35 days. The resulting component values may be negative if resultDate is before startDate.The following example shows how to get the approximate number of months and days between two dates using an existing calendar (gregorian): Note that some computations can take a relatively long time.
- (NSDate) dateByAddingComponents(comps, toDate:date, options:opts)
Returns a new NSDate object representing the absolute time calculated by adding given components to a given date. Some operations can be ambiguous, and the behavior of the computation is calendar-specific, but generally components are added in the order specified.The following example shows how to add 2 months and 3 days to the current date and time using an existing calendar (gregorian): Note that some computations can take a relatively long time.
- (NSDate) dateFromComponents(comps)
Returns a new NSDate object representing the absolute time calculated from given components. When there are insufficient components provided to completely specify an absolute time, a calendar uses default values of its choice. When there is inconsistent information, a calendar may ignore some of the components parameters or the method may return nil. Unnecessary components are ignored (for example, Day takes precedence over Weekday and Weekday ordinals).The following example shows how to use this method to create a date object to represent 14:10:00 on 6 January 1965, for a given calendar (gregorian). Note that some computations can take a relatively long time to perform.
- (Integer) firstWeekday
Returns the index of the first weekday of the receiver.
- (Object) initWithCalendarIdentifier(string)
Initializes a newly-allocated NSCalendar object for the calendar specified by a given identifier.
- (NSLocale) locale
Returns the locale for the receiver.
- (NSRange) maximumRangeOfUnit(unit)
The maximum range limits of the values that a given unit can take on in the receive As an example, in the Gregorian calendar the maximum range of values for the Day unit is 1-31.
- (Integer) minimumDaysInFirstWeek
Returns the minimum number of days in the first week of the receiver.
- (NSRange) minimumRangeOfUnit(unit)
Returns the minimum range limits of the values that a given unit can take on in the receiver. As an example, in the Gregorian calendar the minimum range of values for the Day unit is 1-28.
- (Integer) ordinalityOfUnit(smaller, inUnit:larger, forDate:date)
Returns, for a given absolute time, the ordinal number of a smaller calendar unit (such as a day) within a specified larger calendar unit (such as a week). The ordinality is in most cases not the same as the decomposed value of the unit. Typically return values are 1 and greater. For example, the time 00:45 is in the first hour of the day, and for units Hour and Day respectively, the result would be 1. An exception is the week-in-month calculation, which returns 0 for days before the first week in the month containing the date.Note that some computations can take a relatively long time.
- (NSRange) rangeOfUnit(smaller, inUnit:larger, forDate:date)
Returns the range of absolute time values that a smaller calendar unit (such as a day) can take on in a larger calendar unit (such as a month) that includes a specified absolute time. You can use this method to calculate, for example, the range the Day unit can take on in the Month in which date lies.
- (Boolean) rangeOfUnit(unit, startDate:datep, interval:tip, forDate:date)
Returns by reference the starting time and duration of a given calendar unit that contains a given date.
- (Object) setFirstWeekday(weekday)
Sets the index of the first weekday for the receiver.
- (Object) setLocale(locale)
Sets the locale for the receiver.
- (Object) setMinimumDaysInFirstWeek(mdw)
Sets the minimum number of days in the first week of the receiver.
- (Object) setTimeZone(tz)
Sets the time zone for the receiver.
- (NSTimeZone) timeZone
Returns the time zone for the receiver.