0

I have a chat on my iOS and Android application, and I was using the local timestamp in the message.
I know this is a huge mistake...
I would like to use Firebase timestamp.

On iOS I was using NSDate().timeIntervalSince1970, which is in second.
But FirebaseServerValue.timestamp()is in millisecond, so obviously it doesn't work really well.

  1. Do you know if there is a way to say to Firebase to store the timestamp in second rather than millisecond?
  2. Otherwise, do you have a solution for me?
    I can update the application with Firebase's timestamp, and send a message when an old version is opened, but I know that not everyone will update the application.

Thanks!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
papay0
  • 1,311
  • 1
  • 12
  • 25

1 Answers1

2

Isn't it simply to just divide it by 1000? Then you get seconds...

MaTePe
  • 936
  • 1
  • 6
  • 11
  • Do you know how to do that? FirebaseServerValue.timestamp() is not a number or date, this is an object saying to Firebase to write a server side timestamp. Check that: http://stackoverflow.com/questions/29243060/trying-to-convert-firebase-timestamp-to-nsdate-in-swift – papay0 Sep 27 '16 at 14:45
  • I was taking about when you used the value, does it really matter if you are missing up to 0.5 seconds on the server side? If you always divide the result then you get it back? I guess you will use the data to sort the chat in order or something similar. I just used it to display the time it was sent, then I used minutes. – MaTePe Sep 27 '16 at 14:48
  • See second question, I can do that but let's say during 1 month it will be a mess in my application, but not everyone will update it. If I do the update, it will work for people who did the update and for all the other one it will be written "8 Jun 48710" rather than "27 Sept 2016" – papay0 Sep 27 '16 at 14:57
  • If you are able to determine how the timestamp was set it should be possible to handle it on the client side too I guess. If it's too big, then divide it or set N/A. Not sure about the details of your application, but to me it seems feasible. – MaTePe Sep 27 '16 at 15:01
  • The problem is that this is an iOS application, not a webapp, it can't change the source code without forcing people to update my app. Of course I know how to solve the problem technically but I will need everyone to update the app, and I cannot count on it. – papay0 Sep 27 '16 at 15:03