createdAt timestamp confusion

Hi,

I’m currently implementing chat functionality using the Unity SDK.

I am trying to understand the value that the SDK returns for message.createdAt.

I am trying to construct a DateTime object so that I can format the timestamp.

Normally I would just do this as
var timeStamp = new DateTime(message.createdAt);

However this is giving me a totally wrong value:
Timestamp: 1/2/0001 9:00:34 PM

I imagine this means that the SDK is parsing this value incorrectly, but maybe there is something I am missing? I have tried to query the REST platform directly to see if I can make sense of the data coming in, but no luck so far.

Any advice is appreciated!

Thanks

As you might know, Sendbird provides the timestamp as the form of Unix Time(Unix time - Wikipedia), mainly in milliseconds.
https://sendbird.com/docs/calls/v1/platform-api/guides/miscellaneous#2-timestamps

Could you try to use AddSeconds() like below?
DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, 0); //from start epoch time
start = start.AddSeconds(message.createdAt/1000); //add the seconds to the start DateTime

Hi thanks for that.

The code above does work, but can be written cleaner like this (.net 4.6+)
timestamp = DateTimeOffset.FromUnixTimeMilliseconds(message.CreatedAt).UtcDateTime;

As .NET does not have real support for Unix Timestamps, you might consider making this conversion part of the SDK and add another property for unixTime

Hi,

We really appreciate your feedback!
I will let our engineering team know that.