Advertisement
  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. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    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. Gamecrafter
    Offline

    Gamecrafter

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

    Legoboy0215 Notable Member

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

    Gamecrafter

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

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    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. Gamecrafter
    Offline

    Gamecrafter

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

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    *scream* I can't determine if that is sarcastic or not.
    jojoe77777 likes this.
  8. Gamecrafter
    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. Legoboy0215
    Offline

    Legoboy0215 Notable Member

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

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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. Gamecrafter
    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. Gamecrafter
    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. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I use (string) and (int) all the time.
  14. Gamecrafter
    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. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why wkould I use it if I don't? :)
  16. Gamecrafter
    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. Legoboy0215
    Offline

    Legoboy0215 Notable Member

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

    Legoboy0215 Notable Member

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

    Legoboy0215 Notable Member

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

    Legoboy0215 Notable Member

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

Share This Page

Advertisement