Apple Cocoa / Core Foundation Time — CFAbsoluteTime ↔ Date

Convert Apple CFAbsoluteTime (aka NSTimeInterval, seconds since 2001-01-01 UTC) to human-readable dates — and back. Fractional seconds supported. Private by design.

Display & Quick

Results always include UTC; this adds a local view.
UNIX ↔ CF offset: 978307200 seconds (to/from 1970-01-01 UTC)

1) CFAbsoluteTime / NSTimeInterval → Date

This is what NSDate.timeIntervalSinceReferenceDate returns.

2) Date → CFAbsoluteTime / NSTimeInterval

Interpreted in your current local time zone.
If a zone/offset is provided, it will be respected.

About Apple Cocoa / Core Foundation Time

CFAbsoluteTime (also known as NSTimeInterval when used by NSDate) counts seconds— possibly fractional—since the Apple reference date 2001-01-01T00:00:00Z. This converter translates between that value and human-readable dates, preserving millisecond precision in outputs.

Compared to the UNIX epoch (1970-01-01T00:00:00Z), the Apple reference date occurs exactly 978,307,200 seconds later. Conversions are therefore:

  • CF → UNIX seconds: unix = cf + 978307200
  • UNIX seconds → CF: cf = unix - 978307200

Apple Core Time: Code Snippets

Quick, copyable examples for converting between CFAbsoluteTime (seconds since 2001-01-01T00:00:00Z) and human time.

Swift

// CFAbsoluteTime ("since 2001") ↔ UNIX seconds ("since 1970")
let offset: TimeInterval = 978_307_200

func cfToUnix(_ cf: TimeInterval) -> TimeInterval { cf + offset }
func unixToCf(_ unix: TimeInterval) -> TimeInterval { unix - offset }

// CFAbsoluteTime ↔ Date
func cfToDate(_ cf: TimeInterval) -> Date {
    Date(timeIntervalSince1970: cf + offset)
}
func dateToCf(_ date: Date) -> TimeInterval {
    date.timeIntervalSince1970 - offset
}

Objective-C

static const NSTimeInterval kOffset = 978307200.0;
NSTimeInterval CFToUnix(NSTimeInterval cf) { return cf + kOffset; }
NSTimeInterval UnixToCF(NSTimeInterval unix) { return unix - kOffset; }
NSDate * CFToDate(NSTimeInterval cf) { return [NSDate dateWithTimeIntervalSince1970:(cf + kOffset)]; }
NSTimeInterval DateToCF(NSDate *date) { return [date timeIntervalSince1970] - kOffset; }

JavaScript

const OFFSET = 978307200;
function cfToDate(cf) { return new Date((cf + OFFSET) * 1000); }
function dateToCf(d) { return d.getTime() / 1000 - OFFSET; }

Python

OFFSET = 978_307_200
def cf_to_datetime(cf): 
    import datetime
    return datetime.datetime.fromtimestamp(cf + OFFSET, tz=datetime.timezone.utc)
def datetime_to_cf(dt):
    if dt.tzinfo is None: dt = dt.astimezone()
    return dt.timestamp() - OFFSET

Ruby

OFFSET = 978_307_200.0
def cf_to_time(cf) Time.at(cf + OFFSET).utc end
def time_to_cf(t) t.to_f - OFFSET end

Handy Facts & Gotchas

  • NSDate reference: [NSDate timeIntervalSinceReferenceDate] returns CFAbsoluteTime.
  • Precision: Values are fractional seconds; outputs keep millisecond precision.
  • DST/leap seconds: Stored values are UTC-based; DST only affects display.
  • Plists: Binary plists may store dates as CFAbsoluteTime internally.

Explore more tools