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
gefragt vor einem Jahr228 Aufrufe
1 Antwort
1
Akzeptierte Antwort

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
beantwortet vor einem Jahr
  • Thanks a lot, Joris, It worked now!

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen