question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

Add Hours/Minutes in Current Server Timestamp

Hi, I have used this API in cloudscript to get Server Timestamp. I have the response from API and now I want to add hours or minutes in the timestamp I got from API. How can I do that?

apissdksCloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Sarah Zhang avatar image
Sarah Zhang answered

GetTime API always returns the time as Coordinated Universal Time(UTC). Do you mean you want to do increasing calculation to the time then return the modified UTC?

CloudScript executes JavaScript code, so you can directly use the following statement to get the current UTC, you can use this native JS method instead of PlayFab API GetTime.

    var now = new Date();

So you can use the following function to get the date that current UTC plus one hour.

handlers.plusOneHour = function (args, context) {
    var now = new Date();
    var myTimeStamp = now.setHours(now.getHours() + 1);
    var myDate = new Date(myTimeStamp);
    return myDate;
};

For more advanced questions about time calculation and formatting time in the CloudScript, please refer to the documentation of JavaScript.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.