Apple Cocoa Core Data timestamp to human-readable date
Core Data is a data storage framework for iOS and OS X applications. It is part of the Cocoa API. These timestamps are sometimes called 'Mac absolute time'. A Core Data timestamp counts seconds (or nanoseconds) since midnight, January 1, 2001, GMT. The difference between a Core Data timestamp and a Unix timestamp (seconds since 1/1/1970) is 978307200 seconds.
Cocoa to Unix
Unix to Cocoa
Programming Examples
Learn how to convert Cocoa/Core Data timestamps in Swift and Objective-C:
import Foundation
// Cocoa epoch: January 1, 2001 00:00:00 UTC
let COCOA_EPOCH: TimeInterval = 978307200
// Convert Cocoa timestamp to Date
func cocoaToDate(_ cocoaTimestamp: TimeInterval) -> Date {
let unixSeconds = cocoaTimestamp + COCOA_EPOCH
return Date(timeIntervalSince1970: unixSeconds)
}
// Convert Date to Cocoa timestamp
func dateToCocoa(_ date: Date) -> TimeInterval {
let unixSeconds = date.timeIntervalSince1970
return unixSeconds - COCOA_EPOCH
}
// Example usage
let cocoaTimestamp: TimeInterval = 790782780
let date = cocoaToDate(cocoaTimestamp)
print(date)
let now = Date()
let cocoaTs = dateToCocoa(now)
print("Cocoa timestamp: \(cocoaTs)")
// Using NSDate (Foundation)
let nsDate = NSDate(timeIntervalSince1970: cocoaTimestamp + COCOA_EPOCH)
print(nsDate)Swift uses TimeInterval (Double) for time calculations. NSDate is available for Objective-C compatibility.
What is Cocoa / Core Data / Mac Absolute Time?
Cocoa (Apple's macOS and iOS framework) uses a timestamp format called "Absolute Time" that counts seconds since January 1, 2001, 00:00:00 UTC. This is the epoch used by Core Data, NSDate, and other Apple frameworks. Unlike Unix timestamps which use January 1, 1970 as the epoch, Cocoa timestamps use a later epoch date, making them smaller numbers. This format is commonly used in macOS and iOS applications, especially when working with Core Data or NSDate objects.
Conversion formula:
- Cocoa to Unix:
unix = cocoa + 978307200 - Unix to Cocoa:
cocoa = unix - 978307200
Use cases: macOS/iOS development, Core Data timestamps, NSDate conversion, Apple ecosystem integration, and converting timestamps between Cocoa and Unix formats for cross-platform compatibility. This tool is essential for developers working with Apple platforms.
Frequently Asked Questions
What is a Cocoa timestamp?
Cocoa timestamps are used by macOS and iOS Core Data framework. They count seconds since January 1, 2001, 00:00:00 UTC, which is different from Unix timestamps that use January 1, 1970 as the epoch.
How do I convert a Cocoa timestamp to Unix timestamp?
Enter your Cocoa timestamp in the input field and click convert. The tool will automatically convert it to a Unix timestamp and display the human-readable date. Cocoa timestamps are smaller numbers than Unix timestamps because they use a later epoch date.
What is the difference between Cocoa and Unix timestamps?
Cocoa timestamps use January 1, 2001 as the epoch and measure in seconds, while Unix timestamps use January 1, 1970 as the epoch. Cocoa timestamps are typically smaller numbers because they start from a later date. The difference is 978307200 seconds (about 31 years).