GameSparks Cloud Code - How to get current backend time (preferably time since epoch)

0

Hi,

I want to get current time as milliseconds to store in DynamoDB, along with some player data acquired from the client. So far create a new Event and use some of the below approaches:

const timeInEpoch = ${now};

const timeInEpoch = Date.now();

const timeInEpoch = new Date().getTime();

But it seems to me that none of the above code works, when I try the event with Test Harness, it return error result as: Enter image description here

Is there a way to retrieve this information? Thanks a lot!

Niles
已提问 1 年前228 查看次数
1 回答
1
已接受的回答

Hi Niles!

Here's how you can get the current epoch, in seconds and milliseconds:

const epoch = new Date('1970-01-01T00:00:00Z');
const currentDate = new Date();

const timestamp_ms = currentDate - epoch;
const timestamp = Math.floor(timestamp_ms / 1000);

GameSparks().Logging().Info("Current timestamp, in seconds: " + timestamp);
AWS
Joris_D
已回答 1 年前
  • Thanks a lot, Joris, It worked now!

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则