Mac Developer Library

Developer

CoreFoundation Framework Reference CFDate Reference

Options
Deployment Target:

On This Page
Language:

CFDate Reference

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import CoreFoundation

Objective-C

@import CoreFoundation;

CFDate objects store dates and times that can be compared to other dates and times. CFDate objects are immutable—there is no mutable counterpart for this opaque type.

CFDate provides functions for creating dates, comparing dates, and computing intervals. You use the CFDateCreate function to create CFDate objects. You use the CFDateCompare function to compare two dates, and the CFDateGetTimeIntervalSinceDate function to compute a time interval. Additional functions for managing dates and times are described in Time Utilities Reference

CFDate is “toll-free bridged” with its Cocoa Foundation counterpart, NSDate. What this means is that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. In other words, in a method where you see an NSDate * parameter, you can pass in a CFDateRef, and in a function where you see a CFDateRef parameter, you can pass in an NSDate instance. This also applies to concrete subclasses of NSDate. See Interchangeable Data Types for more information on toll-free bridging.

Functions

  • Compares two CFDate objects and returns a comparison result.

    Declaration

    Swift

    func CFDateCompare(_ theDate: CFDate!, _ otherDate: CFDate!, _ context: UnsafeMutablePointer<Void>) -> CFComparisonResult

    Objective-C

    CFComparisonResult CFDateCompare ( CFDateRef theDate, CFDateRef otherDate, void *context );

    Parameters

    theDate

    The date to compare to otherDate.

    otherDate

    The date to compare to theDate.

    context

    Unused. Pass NULL.

    Return Value

    A Comparison Results value that indicates whether theDate is equal to, less than, or greater than otherDate.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.

  • Creates a CFDate object given an absolute time.

    Declaration

    Swift

    func CFDateCreate(_ allocator: CFAllocator!, _ at: CFAbsoluteTime) -> CFDate!

    Objective-C

    CFDateRef CFDateCreate ( CFAllocatorRef allocator, CFAbsoluteTime at );

    Parameters

    allocator

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    at

    The absolute time to convert to a CFDate object.

    Return Value

    A date object that represents the absolute time at. The caller is responsible for releasing the CFDate object using CFRelease.

    Discussion

    CFDate objects must always be created using absolute time. Time intervals are not supported.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a CFDate object’s absolute time.

    Declaration

    Swift

    func CFDateGetAbsoluteTime(_ theDate: CFDate!) -> CFAbsoluteTime

    Objective-C

    CFAbsoluteTime CFDateGetAbsoluteTime ( CFDateRef theDate );

    Parameters

    theDate

    The date to examine.

    Return Value

    The absolute time of theDate.

    Discussion

    Absolute time is measured in seconds relative to the absolute reference date of Jan 1 2001 00:00:00 GMT. A positive value represents a date after the reference date, a negative value represents a date before it. For example, the absolute time -32940326 is equivalent to December 16th, 1999 at 17:54:34.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.

  • Returns the number of elapsed seconds between the given CFDate objects.

    Declaration

    Swift

    func CFDateGetTimeIntervalSinceDate(_ theDate: CFDate!, _ otherDate: CFDate!) -> CFTimeInterval

    Objective-C

    CFTimeInterval CFDateGetTimeIntervalSinceDate ( CFDateRef theDate, CFDateRef otherDate );

    Parameters

    theDate

    The date to compare to otherDate.

    otherDate

    The date to compare to theDate.

    Return Value

    The number of elapsed seconds between theDate and otherDate. The result is positive if theDate is later than otherDate.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.

  • Returns the type identifier for the CFDate opaque type.

    Declaration

    Swift

    func CFDateGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFDateGetTypeID ( void );

    Return Value

    The type identifier for the CFDate opaque type.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.

Data Types

Miscellaneous

  • A reference to an immutable CFDate object.

    Declaration

    Swift

    typealias CFDateRef = CFDate

    Objective-C

    typedef const struct __CFDate *CFDateRef;

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in OS X v10.0 and later.