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
C
Customer Support
said
over 5 years ago
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.
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.
Fernando Vaquero Merediz
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!
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Fernando Vaquero Merediz
Thank you very much!
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics