ClumsyZombie Posted July 30, 2016 Share Posted July 30, 2016 I have been toying with this Truckers MP API and well 2 days now been able to get everything else figured out. I wanted to pull the game time API into my site and then display it in Human readable. This is what I have so far. <?php $gametime = json_decode(file_get_contents("https://api.truckersmp.com/v2/game_time"), true); ?> <?php echo "Current Game Time: "; echo $gametime['game_time'] ?><br> So I am trying to figure out when I make the call and this display it how can I convert it and show in human readable. When I go to a converter site it says that Current Game Time: 2423486 = Thu, 29 Jan 1970 01:11:26 GMT Is this not EPOCH time that is reported back in the API? Also any way you all know to convert that I would be greatful..... Just looking for some help as i just started hitting this hard and I am a basic php guy so bear with me please. Link to comment Share on other sites More sharing options...
Bomlife Posted July 30, 2016 Share Posted July 30, 2016 <?php $json = file_get_contents("https://api.truckersmp.com/v2/game_time"); $data = json_decode($json); $game_time = $data->game_time; echo date('H:i', mktime(0, $game_time)); ?> Link to comment Share on other sites More sharing options...
Ratcho Posted July 30, 2016 Share Posted July 30, 2016 As @Bomlife showed above. Using date() will allow you to return the time, you could also then return other values such as the year, day, date etc via the same function by changing the values to return in the first parameter of date(). A list of parameters can be found here: http://php.net/manual/en/function.date.php Link to comment Share on other sites More sharing options...
ClumsyZombie Posted July 30, 2016 Author Share Posted July 30, 2016 @Bomlife @illtag Thank you both so much for the help! Link to comment Share on other sites More sharing options...
K4su Posted July 30, 2016 Share Posted July 30, 2016 https://stats.truckersmp.com/api#game_time Quote Game time is expressed in minutes, where 10 real seconds is 1 minute of in-game time. It is number of minutes since 2015-25-10 15:48:32 CET. That's what I found out after reading through the documentation... Link to comment Share on other sites More sharing options...
HumaneWolf Posted July 31, 2016 Share Posted July 31, 2016 Keep in mind that you should NOT load the time from our API on every page load, but add your own caching layer. The documentation even has enough info for you to make your own clock counting game time. HumaneWolf - Website - Twitter - GitHub Ex-Developer Link to comment Share on other sites More sharing options...
ClumsyZombie Posted July 31, 2016 Author Share Posted July 31, 2016 @HumaneWolf Thanks for the information. Link to comment Share on other sites More sharing options...
Recommended Posts