Jump to content


This topic is now archived and is closed to further replies.


Calculate Time

Recommended Posts

This is quite an odd question which I havent found it being asked anywhere else.

Basically Im working on an online web based RPG game. Now I want there to be an in-game time. This in-game time runs a lot faster than real time. I want it so that 1 day real time means 7 days in game time. So what I need to know is how I can display the in-game time on my site.

Eventually I will use AJAX to display a more dynamic/live version of it but for now is there a way which I can just perhaps store the game time in a text file.

Let me know.


Share this post

Link to post
Share on other sites
Do you want in-game time to follow real time, but at a faster rate?  If so, it's probably easier if you calculate game time from real time each time rather than storing it.

Share this post

Link to post
Share on other sites
i'm with btherl on this one. you need to come up with an algorithm to allow you to calculate your exact time based on current time of the day rather than trying to store the time. for one thing, with time moving that quickly, you'll never have your time very accurate if you keep having to update a text file, but in addition to that, if you're calculating the time, you can actually allow people to have their time reflect their own timezones, too. since you're talking about exactly 1 week (168 game hours) each day, you'll be having 7 gameplay hours pass for every 1 hour in real time. with that in the back of your mind, you should be able to write a function to pretty successfully calculate the gametime at any given moment. for instance:
// i know that 1 day = 168 gameplay hours = 7 gameplay days
// 1 hour = 7 gameplay hours
// 3 hours 25 minutes ~ is about 1 gameplay day
// about 8.5 minutes = 1 gameplay hour

// get current hour and minute
list($hour, $min) = explode(':', date('h:i'));

// figure out where in the gameplay week for today you are:
$gpHours = $hour * 7;
$gpMins  = $min * 8.49;

// increment $gpHours 1 for each gamplay hour the minutes represent
$gpHours += floor($gpMins / 60);

// gamplay days is equivalent to how many hours have passed
$gpDays = floor($gpHours / 24);

// gamplay hours are the balance
$gpHours = $gpHours % 24;

// $gpMins = the remainder of the above calculation
$gpMins  = $gpMins % 60;

echo "Today is the $gpDays of the week. The time is {$gpHours}:{$gpMins}.";

obviously, this is very rudimentary code, and you'll need to modify it to fit your needs, but i think you'll get a good feel for how it can work.

good luck

Share this post

Link to post
Share on other sites

The way I have done it was...

I found out the time difference in seconds from a set date & time (which wont change) and the current time. Then I multiplied this by 7 and added it onto the current time.

So now I have the variable $gametime which equals the in game time which is 7 times faster than real time.

The next thing I would like to do is construct some sort of basic calendar based off this speeded up date/time.

If someone could show me how I could just view the current month in a day by day view and then I will modify and expand to allow more months to be viewed.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.