Manngo
Manngo

Reputation: 16379

How does Swift manage dates in CoreData

I have been including a date in my CoreData, and was curious too see what happens behind the scenes with the underlying SQLite database.

I noticed that while integer and varchar are are used for other CoreData attributes, a CoreData Date attribute appears in SQLite as timestamp.

Now I know that SQLite has its quirks, notably:

I also notice that the date is stored in a human-readable format. However, it appears to be a non-standard format which is also off by a few years.

For example:

The ISO8601 exported version above is correct. The SQLite version above is off by 31 years, ignores our DST offset, and doesn’t conform to any standards that I’m aware of.

How does CoreData mange its dates?

Upvotes: 0

Views: 128

Answers (1)

pbasdf
pbasdf

Reputation: 21536

See the documentation for Swift Date. Apple use a different reference date (1/1/2001) from Unix (1/1/1970), which explains the bulk, if not all, of the difference.

Upvotes: 1

Related Questions