-1

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
Riccardo
  • 1,083
  • 2
  • 15
  • 25
samad5353
  • 381
  • 1
  • 5
  • 18
  • 5
    From https://developer.apple.com/documentation/foundation/date: A Date value encapsulate a single point in time, **independent of any particular calendrical system or time zone.** – Martin R Nov 15 '18 at 14:12
  • Possible helpful: [NSDate() or Date() shows the wrong time](https://stackoverflow.com/questions/39937019/nsdate-or-date-shows-the-wrong-time). – Martin R Nov 15 '18 at 14:13

2 Answers2

7

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.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
1

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.

Rainer Schwarz
  • 380
  • 3
  • 9