-2

I want to convert the timestamp I have saved to Firebase to real time time. I have seen some codes here, and watched some youtube videos, but for some odd reason I can't get the timeIntervalSince1970 function up?

The only available function I can call is NSTimeIntervalSince1970. Why is this?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
akvag
  • 57
  • 8
  • 1
    Please show your code with enough context. And where is _codes here_ ? – OOPer Sep 10 '18 at 16:11
  • 1
    Possible duplicate of [Convert Firebase Firestore Timestamp to Date (Swift)?](https://stackoverflow.com/questions/51116381/convert-firebase-firestore-timestamp-to-date-swift) – ielyamani Sep 10 '18 at 17:09

2 Answers2

2

timeIntervalSince1970 is a property of Date. A Firestore Timestamp object is not a Date - it is its own type. If you want to convert it to a Date, you can call its dateValue() method. This will give you a Date, and you can use timeIntervalSince1970 on that.

Or, even better, you can use the seconds property on the Timestamp directly and skip Date altogether.

Doug Stevenson
  • 268,359
  • 30
  • 341
  • 380
-1

You should just be able to use Date().timeIntervalSince1970

Daniel Dramond
  • 1,488
  • 2
  • 14
  • 25