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
demandé il y a un an228 vues
1 réponse
1
Réponse acceptée

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
répondu il y a un an
  • Thanks a lot, Joris, It worked now!

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions