Class: NSDateComponents

Inherits:
NSObject show all

Overview

NSDateComponents encapsulates the components of a date in an extendable, object-oriented manner. It is used to specify a date by providing the temporal components that make up a date and time: hour, minutes, seconds, day, month, year, and so on. It can also be used to specify a duration of time, for example, 5 hours and 16 minutes. An NSDateComponents object is not required to define all the component fields. When a new instance of NSDateComponents is created the date components are set to NSUndefinedDateComponent.

Instance Method Summary (collapse)

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

Instance Method Details

- (NSCalendar) calendar

Returns the calendar of the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

- (NSDate) date

Returns the date of the receiver.

Returns:

- (Integer) day

Returns the number of day units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of day units for the receiver.

- (Integer) era

Returns the number of era units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of era units for the receiver.

- (Integer) hour

Returns the number of hour units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of hour units for the receiver.

- (Boolean) isLeapMonth

Returns whether the month is a leap month.

Returns:

  • (Boolean)

    YES if the month is a leap month, NO otherwise.

- (Integer) minute

Returns the number of minute units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of minute units for the receiver.

- (Integer) month

Returns the number of month units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of month units for the receiver.

- (Integer) quarter

Returns the number of quarters in the calendar.

Returns:

  • (Integer)

    The number of quarters units for the receiver.

- (Integer) second

Returns the number of second units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of second units for the receiver.

- (Object) setCalendar(cal)

Sets the receiver’s calendar. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

Returns:

- (Object) setDay(v)

Sets the number of day units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of day units for the receiver.

Returns:

- (Object) setEra(v)

Sets the number of era units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of era units for the receiver.

Returns:

- (Object) setHour(v)

Sets the number of hour units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of hour units for the receiver.

Returns:

- (Object) setLeapMonth(lm)

Sets the month as a leap month.

Parameters:

  • lm (Boolean)

    YES if the month is a leap month, NO otherwise.

Returns:

- (Object) setMinute(v)

Sets the number of minute units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of minute units for the receiver.

Returns:

- (Object) setMonth(v)

Sets the number of month units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of month units for the receiver.

Returns:

- (Object) setQuarter(v)

Sets the number of quarters in the calendar. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of quarters units for the receiver.

Returns:

- (Object) setSecond(v)

Sets the number of second units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of second units for the receiver.

Returns:

- (Object) setTimeZone(tz)

Sets the receiver’s time zone. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

Returns:

- (Object) setWeek(v)

Sets the number of week units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of week units for the receiver.

Returns:

- (Object) setWeekday(v)

Sets the number of weekday units for the receiver. Weekday units are the numbers 1 through n, where n is the number of days in the week. For example, in the Gregorian calendar, n is 7 and Sunday is represented by 1.This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of weekday units for the receiver.

Returns:

- (Object) setWeekdayOrdinal(v)

Sets the ordinal number of weekday units for the receiver. Weekday ordinal units represent the position of the weekday within the next larger calendar unit, such as the month. For example, 2 is the weekday ordinal unit for the second Friday of the month.This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The ordinal number of weekday units for the receiver.

Returns:

- (Object) setWeekOfMonth(week)

Sets the week of the month. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • week (Integer)

    The week number of the month.

Returns:

- (Object) setWeekOfYear(week)

Sets the week of the year. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • week (Integer)

    The week number of the year.

Returns:

- (Object) setYear(v)

Sets the number of year units for the receiver. This value will be interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • v (Integer)

    The number of year units for the receiver.

Returns:

- (Object) setYearForWeekOfYear(year)

Sets the year for the week of the year. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Parameters:

  • year (Integer)

    The year when the calendar is being interpreted as a week-based calendar.

Returns:

- (NSTimeZone) timeZone

Returns the receiver’s time zone. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

- (Integer) week

Returns the number of week units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of week units for the receiver.

- (Integer) weekday

Returns the number of weekday units for the receiver. Weekday units are the numbers 1 through n, where n is the number of days in the week. For example, in the Gregorian calendar, n is 7 and Sunday is represented by 1.This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of weekday units for the receiver.

- (Integer) weekdayOrdinal

Returns the ordinal number of weekday units for the receiver. Weekday ordinal units represent the position of the weekday within the next larger calendar unit, such as the month. For example, 2 is the weekday ordinal unit for the second Friday of the month.This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The ordinal number of weekday units for the receiver.

- (Integer) weekOfMonth

Returns the week of the month. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The week number of the month.

- (Integer) weekOfYear

Returns the week of the year. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The week number of the year.

- (Integer) year

Returns the number of year units for the receiver. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The number of year units for the receiver.

- (Integer) yearForWeekOfYear

Returns the year for the week of the year. This value is interpreted in the context of the calendar with which it is used—see “Calendars, Date Components, and Calendar Units” in Date and Time Programming Guide.

Returns:

  • (Integer)

    The year number for the week of the year.