I am converting my current date with timeIntervalSince1970
In which timezone am I receiving it? Currently I'm in Dubai timezone; is this converted date in UTC Format?
let epochTime = Date().timeIntervalSince1970
I am converting my current date with timeIntervalSince1970
In which timezone am I receiving it? Currently I'm in Dubai timezone; is this converted date in UTC Format?
let epochTime = Date().timeIntervalSince1970
A Date
is an absolute point in time. It does not have a time zone. If you started a stopwatch at "00:00:00 UTC on 1 January 1970," the result of timeIntervalSince1970
would be the number of seconds that had elapsed on that stopwatch. It doesn't matter if you take that stopwatch on a plane and fly anywhere in the world. You could fly to the Moon. It doesn't matter. The same number of seconds will have elapsed (ignoring relativistic effects and the occasional leap second to keep it in sync with the Earth's changing rotation speed).
Time zones only matter when you want to turn that absolute point in time into a human-readable string (in which case you use a DateFormatter
) or when you want to convert it into calendar units (using DateComponents
and a specific Calendar
).
A lot of confusion comes from printing Date
objects, which come out with something like "2018-11-15 14:19:27 +0000" but that doesn't mean the point of time is "in" the "+0000" time zone. This is just a handy format for displaying to programmers to assist in debugging. If you want a string, you must use a DateFormatter
.
The returned value from timeIntervalSince1970
is a TimeInterval (aka Double) since the date '1970-01-01 00:00:00.000' in seconds that elapsed until the specific timestamp.