Sign In Register

How can we help you today?

Start a new topic
Answered

Server time is not correct?

Hello, I'm trying to get the time from the server to use in my game. But the time I get is not correct. Anyone does this?
My cloud code is this:

var myDate = new Date();

var myDay = myDate.getUTCDay();

var myMonth = myDate.getUTCMonth();

var myYear = myDate.getFullYear();


var currentItem = {

        "myDay" : myDay,

        "myMonth" : myMonth,

        "myYear" : myYear,

    };

    

Spark.setScriptData("TIME", currentItem);


Today (5-9-2017) i'm getting the date 2-8-2017.

Anyone know why?


I tried with getDay(), getMonth() and getYear() too, but I get 2-8-117


Thank you!


Best Answer

Hi Fernando,


In JavaScript the day and month both start from 0. So what you're seeing here is correct. getUTCDay() will get the day of the week.Sunday is 0 so Tuesday is 2. To get the day of the month you need to use var myDay = myDate.getDate();. You can read more about dates here.


Regards,

Liam


Answer

Hi Fernando,


In JavaScript the day and month both start from 0. So what you're seeing here is correct. getUTCDay() will get the day of the week.Sunday is 0 so Tuesday is 2. To get the day of the month you need to use var myDay = myDate.getDate();. You can read more about dates here.


Regards,

Liam


1 person likes this

Thank you very much!

Login to post a comment