iOS Developer Library

Developer

CoreFoundation Framework Reference CFTimeZone Reference

Options
Deployment Target:

On This Page
Language:

CFTimeZone Reference

CFTimeZone defines the behavior of time zone objects. Time zone objects represent geopolitical regions. Consequently, these objects have names for these regions. Time zone objects also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time).

CFTimeZone provides several functions to create time zone objects: CFTimeZoneCreateWithName and CFTimeZoneCreateWithTimeIntervalFromGMT. CFTimeZone also permits you to set the default time zone within your application using the CFTimeZoneSetDefault function. You can access this default time zone at any time with the CFTimeZoneCopyDefault function.

CFTimeZone is “toll-free bridged” with its Cocoa Foundation counterpart, NSTimeZone. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSTimeZone * parameter, you can pass in a CFTimeZoneRef, and in a function where you see a CFTimeZoneRef parameter, you can pass in an NSTimeZone instance. This fact also applies to concrete subclasses of NSTimeZone. See Toll-Free Bridged Types for more information on toll-free bridging.

Functions

  • Returns the time zone object identified by a given name or abbreviation.

    Declaration

    Swift

    func CFTimeZoneCreateWithName(_ allocator: CFAllocator!, _ name: CFString!, _ tryAbbrev: Boolean) -> CFTimeZone!

    Objective-C

    CFTimeZoneRef CFTimeZoneCreateWithName ( CFAllocatorRef allocator, CFStringRef name, Boolean tryAbbrev );

    Parameters

    allocator

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

    name

    The name or abbreviation of the time zone to obtain. The name may be in any of the formats understood by the system, for example "EST", "Etc/GMT-2", "America/Argentina/Buenos_Aires", "Europe/Monaco", "US/Pacific", or "posixrules". For a complete list of system names, you can see the output of CFTimeZoneCopyKnownNames.

    tryAbbrev

    If false, assumes name is not an abbreviation and searches the time zone information directory for a matching name. If true, tries to resolve name using the abbreviation dictionary first before searching the information dictionary.

    Return Value

    A time zone corresponding to name, or NULL if no match was found. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a time zone object for the specified time interval offset from Greenwich Mean Time (GMT).

    Declaration

    Swift

    func CFTimeZoneCreateWithTimeIntervalFromGMT(_ allocator: CFAllocator!, _ ti: CFTimeInterval) -> CFTimeZone!

    Objective-C

    CFTimeZoneRef CFTimeZoneCreateWithTimeIntervalFromGMT ( CFAllocatorRef allocator, CFTimeInterval ti );

    Parameters

    allocator

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

    ti

    The offset, from GMT, of the new time zone.

    Return Value

    A new time zone whose offset from GMT is given by the interval ti. The name of the new time zone is GMT +/- the offset, in hours and minutes. Time zones created with this function never have daylight savings, and the offset is constant no matter what the date. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Creates a time zone with a given name and data.

    Declaration

    Swift

    func CFTimeZoneCreate(_ allocator: CFAllocator!, _ name: CFString!, _ data: CFData!) -> CFTimeZone!

    Objective-C

    CFTimeZoneRef CFTimeZoneCreate ( CFAllocatorRef allocator, CFStringRef name, CFDataRef data );

    Parameters

    allocator

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

    name

    The name of the time zone to create.

    data

    The data to use to initialize the time zone. The contents of the data should be the same as that found within the time-zone files located at /usr/share/zoneinfo.

    Return Value

    A time zone corresponding to name and data. Ownership follows the The Create Rule.

    Discussion

    You typically do not call this function directly. Use the CFTimeZoneCreateWithName function to obtain a time zone given its name.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a dictionary holding the mappings of time zone abbreviations to time zone names.

    Declaration

    Swift

    func CFTimeZoneCopyAbbreviationDictionary() -> CFDictionary!

    Objective-C

    CFDictionaryRef CFTimeZoneCopyAbbreviationDictionary ( void );

    Return Value

    A dictionary containing the mappings of time zone abbreviations to time zone names. Ownership follows the The Create Rule.

    Discussion

    More than one time zone may have the same abbreviation. For example, US/Pacific and Canada/Pacific both use the abbreviation "PST." In these cases this function chooses a single name to map the abbreviation to.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the abbreviation of a time zone at a specified date.

    Declaration

    Swift

    func CFTimeZoneCopyAbbreviation(_ tz: CFTimeZone!, _ at: CFAbsoluteTime) -> CFString!

    Objective-C

    CFStringRef CFTimeZoneCopyAbbreviation ( CFTimeZoneRef tz, CFAbsoluteTime at );

    Parameters

    tz

    The time zone to use.

    at

    The absolute time at which to obtain the abbreviation.

    Return Value

    A string containing the time zone abbreviation of at. Ownership follows the The Create Rule.

    Discussion

    Note that the abbreviation may be different at different dates. For example, during daylight savings time the US/Eastern time zone has an abbreviation of "EDT." At other times, its abbreviation is "EST."

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the default time zone set for your application.

    Declaration

    Swift

    func CFTimeZoneCopyDefault() -> CFTimeZone!

    Objective-C

    CFTimeZoneRef CFTimeZoneCopyDefault ( void );

    Return Value

    A time zone representing the default time zone set for your application, or the system time zone if no default is set. Ownership follows the The Create Rule.

    Discussion

    If no default time zone is set, this function simply returns the result of the CFTimeZoneCopySystem function.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the time zone currently used by the system.

    Declaration

    Swift

    func CFTimeZoneCopySystem() -> CFTimeZone!

    Objective-C

    CFTimeZoneRef CFTimeZoneCopySystem ( void );

    Return Value

    A time zone representing the time zone currently used by the system, or the GMT time zone if the current zone cannot be determined. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Sets the default time zone for your application the given time zone.

    Declaration

    Swift

    func CFTimeZoneSetDefault(_ tz: CFTimeZone!)

    Objective-C

    void CFTimeZoneSetDefault ( CFTimeZoneRef tz );

    Parameters

    tz

    The time zone to use as default.

    Discussion

    There can be only one default time zone, so by setting a new default time zone, you lose the previous one.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of strings containing the names of all the time zones known to the system.

    Declaration

    Swift

    func CFTimeZoneCopyKnownNames() -> CFArray!

    Objective-C

    CFArrayRef CFTimeZoneCopyKnownNames ( void );

    Return Value

    An array containing CFString objects representing all the known time zone names. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Clears the previously determined system time zone, if any.

    Declaration

    Swift

    func CFTimeZoneResetSystem()

    Objective-C

    void CFTimeZoneResetSystem ( void );

    Discussion

    If the default time zone is set to the same value as the system time zone or has not been explicitly set, this function clears it as well.

    Subsequent calls to CFTimeZoneCopySystem will attempt to re-determine the system time zone.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Sets the abbreviation dictionary to a given dictionary.

    Declaration

    Swift

    func CFTimeZoneSetAbbreviationDictionary(_ dict: CFDictionary!)

    Objective-C

    void CFTimeZoneSetAbbreviationDictionary ( CFDictionaryRef dict );

    Parameters

    dict

    A dictionary containing key-value pairs for looking up time zone names given their abbreviations. The keys should be CFString objects containing the abbreviations; the values should be CFString objects containing their corresponding geopolitical region names.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the geopolitical region name that identifies a given time zone.

    Declaration

    Swift

    func CFTimeZoneGetName(_ tz: CFTimeZone!) -> CFString!

    Objective-C

    CFStringRef CFTimeZoneGetName ( CFTimeZoneRef tz );

    Parameters

    tz

    The time zone to analyze.

    Return Value

    A string containing the geopolitical region name that identifies tz. Ownership follows the The Get Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the localized name of a given time zone.

    Declaration

    Swift

    func CFTimeZoneCopyLocalizedName(_ tz: CFTimeZone!, _ style: CFTimeZoneNameStyle, _ locale: CFLocale!) -> CFString!

    Objective-C

    CFStringRef CFTimeZoneCopyLocalizedName ( CFTimeZoneRef tz, CFTimeZoneNameStyle style, CFLocaleRef locale );

    Parameters

    tz

    The time zone to analyze.

    style

    The style for the returned name.

    locale

    The locale for which to localize the returned name.

    Return Value

    The name of tz localized for locale. Ownership follows the The Create Rule.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the difference in seconds between the receiver and Greenwich Mean Time (GMT) at the specified date.

    Declaration

    Swift

    func CFTimeZoneGetSecondsFromGMT(_ tz: CFTimeZone!, _ at: CFAbsoluteTime) -> CFTimeInterval

    Objective-C

    CFTimeInterval CFTimeZoneGetSecondsFromGMT ( CFTimeZoneRef tz, CFAbsoluteTime at );

    Parameters

    tz

    The time zone to analyze.

    at

    The date at which the interval is to be computed.

    Return Value

    The difference in seconds between tz and GMT at the specified date, at.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the data that stores the information used by a time zone.

    Declaration

    Swift

    func CFTimeZoneGetData(_ tz: CFTimeZone!) -> CFData!

    Objective-C

    CFDataRef CFTimeZoneGetData ( CFTimeZoneRef tz );

    Parameters

    tz

    The time zone to analyze.

    Return Value

    The data used to store tz. Ownership follows the The Get Rule. May be NULL if the timezone does not have any data or use Olson data for its information.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the type identifier for the CFTimeZone opaque type.

    Declaration

    Swift

    func CFTimeZoneGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFTimeZoneGetTypeID ( void );

    Return Value

    The type identifier for the CFTimeZone opaque type.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

Data Types

Miscellaneous

  • Index type for constants used to specify styles of time zone names.

    Declaration

    Swift

    enum CFTimeZoneNameStyle : CFIndex { case Standard case ShortStandard case DaylightSaving case ShortDaylightSaving case Generic case ShortGeneric }

    Objective-C

    typedef CFIndex CFTimeZoneNameStyle;

    Discussion

    For values, see Time Zone Name Styles.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • A reference to a CFTimeZone object.

    Declaration

    Swift

    typealias CFTimeZoneRef = CFTimeZone

    Objective-C

    typedef const struct __CFTimeZone *CFTimeZoneRef;

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

Constants

  • Name of the notification posted when the time zone changes.

    Declaration

    Swift

    let kCFTimeZoneSystemTimeZoneDidChangeNotification: CFString!

    Objective-C

    const CFStringRef kCFTimeZoneSystemTimeZoneDidChangeNotification;

    Constants

    • kCFTimeZoneSystemTimeZoneDidChangeNotification

      kCFTimeZoneSystemTimeZoneDidChangeNotification

      Name of the notification posted when the system time zone changes.

      The object of the notification is the previous system time zone object. This notification carries no user info.

      Keep in mind that there is no order in how notifications are delivered to observers; frameworks or other parts of your code may also be observing this notification to take their own actions, and these may not have occurred by the time you receive the notification.

      Available in iOS 2.0 and later.

  • Constants to specify styles for time zone names.

    Declaration

    Swift

    enum CFTimeZoneNameStyle : CFIndex { case Standard case ShortStandard case DaylightSaving case ShortDaylightSaving case Generic case ShortGeneric }

    Objective-C

    typedef enum : CFIndex { kCFTimeZoneNameStyleStandard, kCFTimeZoneNameStyleShortStandard, kCFTimeZoneNameStyleDaylightSaving, kCFTimeZoneNameStyleShortDaylightSaving, kCFTimeZoneNameStyleGeneric, kCFTimeZoneNameStyleShortGeneric } CFTimeZoneNameStyle;

    Constants

    • Standard

      kCFTimeZoneNameStyleStandard

      Specifies the standard name style; for example, “Central Standard Time” for the Central time zone.

      Available in iOS 2.0 and later.

    • ShortStandard

      kCFTimeZoneNameStyleShortStandard

      Specifies the short standard name style; for example, “CST” for the Central time zone.

      Available in iOS 2.0 and later.

    • DaylightSaving

      kCFTimeZoneNameStyleDaylightSaving

      Specifies the daylight saving name style; for example, “Central Daylight Time” for the Central time zone.

      Available in iOS 2.0 and later.

    • ShortDaylightSaving

      kCFTimeZoneNameStyleShortDaylightSaving

      Specifies the short daylight saving name style; for example, “CDT” for the Central time zone.

      Available in iOS 2.0 and later.

    • Generic

      kCFTimeZoneNameStyleGeneric

      Specifies the generic name style, which does not distinguish between daylight saving and standard time; for example, “Central Time” for the Central time zone.

      Available in iOS 2.0 and later.

    • ShortGeneric

      kCFTimeZoneNameStyleShortGeneric

      Specifies the short generic name style, which does not distinguish between daylight saving and standard time; for example, “CT” for the Central time zone.

      Available in iOS 2.0 and later.

    Discussion

    These constants are used with the function CFTimeZoneCopyLocalizedName.