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
질문됨 일 년 전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
답변함 일 년 전
  • Thanks a lot, Joris, It worked now!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인