Hours and minutes online
#1

I was wondering, is there a way to split decimal or float values? Something like:

Player is online for 3 hours and 5 minutes since he logged in, which is 12600 (stored) seconds. So 12600 divided by 3600 seconds (in an hour) is equal to 3.5 and now I want to display:

PHP код:
NameJohn Doe Online3 hours and 5 minutes 
If there's a better way to do it then I'd like to know. Thank you!
Reply
#2

explain more
Reply
#3

Hmm, okay. I have a timer that adds +1 to the player's online seconds. And I want to show how many hours and minutes he or she is online by using those collected seconds.

So for example, from the time that the player logged in, he's been on for 2 hours and 32 minutes which 8352 seconds in total. Now, what I want to do is to convert 8352 seconds in hours and minutes.

If the player uses /online command, it would show: Name: John Doe | Online: 2 hours 32 minutes
Reply
#4

PHP код:
OnlineTime[playerid]=NetStats_GetConnectedTime(playerid)/1000 //Converting MilliSeconds to Seconds
Seconds OnlineTime[playerid] % 60
Minutes 
= (OnlineTime[playerid]/60)%60
Hours 
= (OnlineTime[playerid]/60)/60 
Reply
#5

Wow, it's that simple. Never thought of it. Thank you so much!

To be honest, I did a bunch of worthless things like dividing seconds into hours then converting them into string then replace the decimal point into a comma using sscanf and put them each on a variable. But oh well, thank you! Reputation up!
Reply
#6

Sometimes seemingly hard things can be so simple..
Quote:
Originally Posted by SomeoneOnceSaid
Make every moment of your life worth it, it only comes once and once is enough.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)