GameSparks云代码 - 如何获取当前后端时间

0

【以下的问题经过翻译处理】 我想获取当前时间的毫秒数,并将其与从客户端获取的某些玩家数据一起存储在DynamoDB中。到目前为止,创建了一个新的事件并使用了以下方法之一:

const timeInEpoch = ${now};

const timeInEpoch = Date.now();

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

但我觉得上述代码都不起作用。当我尝试使用Test Harness测试事件时,它会返回错误结果: Enter image description here

有没有办法检索这些信息?非常感谢!

profile picture
EXPERT
asked 6 months ago15 views
1 Answer
0

【以下的回答经过翻译处理】 下面是如何获取当前时代的秒数和毫秒数的方法:

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);

profile picture
EXPERT
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions