Next Page > Hide TOC

CFDate Reference

Derived from
Framework
CoreFoundation/CoreFoundation.h
Declared in
CFDate.h
Companion guides

Overview

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 Core 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

CFDateCompare

Compares two CFDate objects and returns a comparison result.

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 CFComparisonResult value that indicates whether theDate is equal to, less than, or greater than otherDate.

Availability
Declared In
CFDate.h

CFDateCreate

Creates a CFDate object given an absolute time.

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. Ownership follows the Create Rule.

Discussion

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

Availability
Related Sample Code
Declared In
CFDate.h

CFDateGetAbsoluteTime

Returns a CFDate object’s absolute time.

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.

Availability
Declared In
CFDate.h

CFDateGetTimeIntervalSinceDate

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

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.

Availability
Declared In
CFDate.h

CFDateGetTypeID

Returns the type identifier for the CFDate opaque type.

CFTypeID CFDateGetTypeID (
   void
);

Return Value

The type identifier for the CFDate opaque type.

Availability
Related Sample Code
Declared In
CFDate.h

Data Types

CFDateRef

A reference to an immutable CFDate object.

typedef const struct __CFDate *CFDateRef;

Availability
Declared In
CFDate.h

Next Page > Hide TOC


© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-12-06)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.