1

I am trying to get the dates of the message send date in String format from sendbird messages, but don't know how to deserialize the messages.

currently I am just getting a mess of numbers like follows:

1506267806611

I currently store the serialized date in the variable below, but can't figure out what's needed to deserialize in swift 3

var msgDate = userMessage.createdAt
Drew
  • 1,341
  • 3
  • 13
  • 18

2 Answers2

0

That's a timestamp. You can convert it to a date using

Date(timeIntervalSince1970: msgDate)
Bruno Rocha
  • 998
  • 8
  • 13
  • 1
    What is the first section of the date returned? `49701-09-23 04:03:31 +0000` – Drew Sep 28 '17 at 15:06
  • At first glance it appeared to be a Timestamp, so in this case I think it would be better to look into Sendbird's documentation to see what format the dates are in. – Bruno Rocha Sep 28 '17 at 15:24
  • for this case the answer sufficed, as I am parsing the string and dropping the year anyway. As long as I got the month, day and time I am all set. I was just curious – Drew Sep 28 '17 at 15:30
0

You should divide it by 1000 to change it to seconds not milliseconds, so it will be like:

let msgDate = Date.init(timeIntervalSince1970: TimeInterval(userMessage.createdAt) / 1000 )
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
Rasheed
  • 131
  • 1
  • 6