1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Seconds value to string?

Comments in 'Plugin Development' started by Legoboy0215, Sep 26, 2015.

1. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
How can I convert a value (Float whatever) like 1.5 to 1:30?
The 1.5 is minutes and 1:30 is the minutes:seconds.
Thanks!
2. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
Legoboy0215 likes this.
3. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
Thanks! I will try it WITHOUT copying and pasting before I understand it.
4. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
But if you copy and paste, then you'll regret it... If you're planning on to copy and paste, describe to me how it works before you do so.
5. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
Okay then.
Introduction / Links (For noobs):
floor()
%
Explanation:
PHP:
``` <?php    public function getFormattedTime(){ //A new public function        \$hour = floor(\$this->getTime() / 3600); //Dividing \$this->getTime() (Which is an integer that represents number of seconds) by 3600 (3600 seconds in a hour) and floor() it.        \$minute = floor((\$this->getTime() / 60) - (\$hour * 60)); //Dividing \$this->getTime() by 60 (60 seconds in a minute) and floor()-ing it. Subtract The number of hours multiplied by 60 (Which is the hours we already calculated)        \$second = floor(\$this->getTime() % 60); //Get the remainder of \$this->getTime and 60.        return \$hour." hr ".\$minute." min ".\$second." sec"; //YAY!    } ```
Last edited: Sep 26, 2015
6. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
*clap clap clap*
7. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
*scream* I can't determine if that is sarcastic or not.
jojoe77777 likes this.
8. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
Not sarcastic. You actually understand the code(after you searched it up, but same thing). What do you need it for anyways?
Legoboy0215 likes this.
9. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
No, I did not look it up. I though if I did not put the links you would disqualify me
Secret... PM me if you wanna know (Why would you want to know )
10. Offline

PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,293
Plugins:
11
Minecraft User:
It is faster to use (int) instead of floor(), if your nunber is smaller than PHP_INT_MAX (for timestamps, that is the value for some time in year 2038).
11. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
Okay, thanks. But what's difference between intval() and (int)? Which one would be better to use(in this situation)?
Last edited: Sep 26, 2015
12. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
Thanks. So I'm guessing I should use (int). But before I use it, I'd like to ask if there are there any downsides to using (int).
13. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
I use (string) and (int) all the time.
14. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
And I'm assuming you know how they work and what they can be used for?
15. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
Why wkould I use it if I don't?
16. Offline

Gamecrafter

Joined:
Nov 20, 2014
Posts:
978
Plugins:
9
*clap clap clap* You're learning, and that's good. How often do you look at code from my plugins? I'm just curious.
17. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
Not really now, but a lot before. I look at my own the most
18. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
I kinda hated you back then too .
I don't look at plugins, I look and try to understand the code.
19. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
You won't recall because I don't announce that
20. Offline

Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,723
Minecraft User:
I registered on Nov 2, 2014 but started to be active on March 3, 2015.