Cocoa Core Data timestamp converter.
Apple's Cocoa framework (used in macOS and iOS) represents dates as NSTimeInterval values: seconds since January 1, 2001 UTC. This format appears in Core Data stores, plist files, and iOS app data. This converter handles both directions.
What is a Cocoa timestamp?
Apple's Cocoa framework (used in macOS and iOS development) uses NSDate to represent points in time. Internally, NSDate stores a 64-bit floating-point number called NSTimeInterval, the number of seconds (with fractional precision) since January 1, 2001, 00:00:00 UTC.
You'll encounter Cocoa timestamps when:
- Inspecting Core Data SQLite databases (the
Z-prefixed timestamp columns) - Reading binary plist (
.plist) files - Working with iOS / macOS app data forensically
- Reading exported data from Apple apps (Health, Notes, etc.)
- Debugging Swift / Objective-C code that serializes dates
Why 2001?
The reference date is 2001-01-01 00:00:00 UTC. Core Foundation calls it the absolute reference date. NSTimeInterval is a 64-bit double, so dates before 2001 are simply negative numbers.
Where you'll see it in practice
Core Data SQLite
-- Core Data stores timestamps in columns named ZDATE, ZCREATEDAT, ZTIMESTAMP, etc.
-- The values are Cocoa timestamps (REAL type in SQLite).
SELECT
Z_PK,
ZCREATEDAT,
datetime(ZCREATEDAT + 978307200, 'unixepoch') AS readable
FROM ZNOTE;
Binary plist
When NSDate is serialized in a binary plist, the timestamp is stored as an 8-byte floating-point value preceded by the 0x33 type marker.
Conversion formulas
Cocoa → Unix seconds
unix_seconds = cocoa_seconds + 978307200
Unix seconds → Cocoa
cocoa_seconds = unix_seconds - 978307200
The constant 978307200 is the number of seconds from 1970-01-01 to 2001-01-01 UTC.
Code examples
Swift
import Foundation
// Cocoa timestamp to Date
let cocoa: TimeInterval = 757382400
let date = Date(timeIntervalSinceReferenceDate: cocoa)
print(date) // 2025-01-01 00:00:00 +0000
// Date to Cocoa timestamp
let now = Date()
let cocoaTimestamp = now.timeIntervalSinceReferenceDate
// Cocoa to Unix
let unixTimestamp = date.timeIntervalSince1970
Python
from datetime import datetime, timezone
COCOA_OFFSET = 978307200
def cocoa_to_datetime(cocoa_sec: float) -> datetime:
return datetime.fromtimestamp(cocoa_sec + COCOA_OFFSET, tz=timezone.utc)
def datetime_to_cocoa(dt: datetime) -> float:
return dt.timestamp() - COCOA_OFFSET
JavaScript
const COCOA_OFFSET = 978307200;
function cocoaToDate(cocoaSec) {
return new Date((cocoaSec + COCOA_OFFSET) * 1000);
}
function dateToCocoa(date) {
return Math.floor(date.getTime() / 1000) - COCOA_OFFSET;
}
Tip: Inspecting Core Data files
Core Data stores its data in SQLite files inside the app's Application Support directory. On macOS:
~/Library/Containers/<bundle-id>/Data/Library/Application Support/<app>/
Open the .sqlite file with any SQLite client. Timestamp columns will be readable as REAL values; convert them with the formula above to get human-readable dates.
Last updated: