Hello, i wanted my shops to automatic change the stock after some time, so i thought of use the hours and minutes of Date() function, but the problem is when someone play around midnight that the hour start back to 0 and the restock will not happen…how can i solve that?
Could you please provide your question by code and comments?
Really i haven’t done the code yet but it will be approximately like this
var now = new Date();
var timestamp = "[" + now.getHours() + ":" + now.getMinutes()"]";
this.player[btype][obj].time=timestamp;
this.shopInventory.push(this.player[btype][obj]);
where btype is the type of the database for shop and obj the number of item in the database
when i access the shop inventory saved like this i get the time when it has been created if a given amount of time is passed the database is cleared and rebuilt. But if it’s been created and 23.55 and i want to restock it every 10 mins…it should be 00.05 so i can’t use a > function coz 00.05 is < than 23.55 … so i should need a time that comprise date and time in a format like 20161204235500 that is < 20161205000500 … i hope my problem is clear enough
Okay. Seems like I got it.
You can rid of it by next way:
var currentTime = new Date();
// Mon Dec 05 2016 01:55:48 GMT+0300 (RTZ 2 (зима))
var nextStockTimestamp = currentTime.getTime() + (10 * 60000) // 10 mins * 60 secs
// 1480892748468
var nextStockDate = new Date(nextStockTimestamp);
// Mon Dec 05 2016 02:05:48 GMT+0300 (RTZ 2 (зима))
I see, i was thinking to use var now =new Date(year, month, day, hours, minutes); but getTime is much more easy. Thanks a lot @mikefinch