<!--
{
  "availability" : [
    "iOS: 2.0.0 - 8.0.0",
    "iPadOS: 2.0.0 - 8.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.4.0 - 10.10.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFAbsoluteTimeGetDifferenceAsGregorianUnits(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFAbsoluteTimeGetDifferenceAsGregorianUnits"
  },
  "title" : "CFAbsoluteTimeGetDifferenceAsGregorianUnits(_:_:_:_:)"
}
-->

# CFAbsoluteTimeGetDifferenceAsGregorianUnits(_:_:_:_:)

Computes the time difference between two specified absolute times and returns the result as an interval in Gregorian units.

```
func CFAbsoluteTimeGetDifferenceAsGregorianUnits(_ at1: CFAbsoluteTime, _ at2: CFAbsoluteTime, _ tz: CFTimeZone!, _ unitFlags: CFOptionFlags) -> CFGregorianUnits
```

## Parameters

`at1`

An absolute time.

`at2`

An absolute time.

`tz`

The time zone to use for time correction. Pass `NULL` for GMT.

`unitFlags`

A mask that specifies which Gregorian unit fields to use when converting the absolute time difference into a Gregorian interval. See [`CFGregorianUnitFlags`](/documentation/CoreFoundation/CFGregorianUnitFlags) for a list of values from which to construct the mask.

## Return Value

The difference between the specified absolute times (as `at1 - at2`—if `at1` is earlier than `at2`, the result is negative) expressed in the units specified by `unitFlags`.

## Discussion

The temporal difference is expressed as accurately as possible, given the units specified. For example, if you asked for the number of months and hours between 2:30pm on April 8 2005 and 5:45pm September 9 2005, the result would be 5 months and 27 hours.

The following example prints the number of hours and minutes between the current time (now) and the reference date (1 January 2001 00:00:00 GMT).

```objc
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent ();
 
CFGregorianUnits units = CFAbsoluteTimeGetDifferenceAsGregorianUnits
    (now, 0, NULL, (kCFGregorianUnitsHours | kCFGregorianUnitsMinutes));
 
CFStringRef output = CFStringCreateWithFormat
    (NULL, 0, CFSTR("hours: %d; minutes: %d"), units.hours, units.minutes);
CFShow(output);
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)