Solved millis to seconds to minutes etc?

Discussion in 'Plugin Development' started by OverDodo, Feb 21, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    OverDodo

    Hey,

    I want to have a 5-Min-Cooldown for my Report-Plugin. I used this method, but it wouldn´t work!



    PHP:
    if (reportcd.containsKey(player.getName())) { 
                       
                        
    long secondsLeft = ((reportcd.get(player.getName()) + 300)- (System.currentTimeMillis())); // Hier Prüfen wir ob der Spieler noch warten muss ( die + 20 sind die sekunden die der Spieler warten muss (20 sekunden))
                        
    if (secondsLeft 0) {
                                
    int seconds 0;
                               
    int minutes 0;
                               
    int hours 0;
                               
    int days 0;
                               while (
    secondsLeft 1000) {
                                   
    secondsLeft -= 1000;
                                   ++
    seconds;
                               }
                               while (
    seconds 60) {
                                   
    seconds -= 60;
                                   ++
    minutes;
                               }
                               while (
    minutes 60) {
                                   
    minutes -= 60;
                                   ++
    hours;
                               }
                               while (
    hours 24) {
                                   
    hours -= 24;
                                   ++
    days;
                               }
    Please help?
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    OverDodo

    That doesn´t help me at all.. I need it in a CoolDown for my Report-System
     
  4. Offline

    timtower Administrator Administrator Moderator

    @OverDodo Third code block in the first post:
    Code:
    int seconds =(int)(milliseconds /1000)%60;
    int minutes =(int)((milliseconds /(1000*60))%60);
    int hours =(int)((milliseconds /(1000*60*60))%24);
    If that doesn't help then please tell what you need.
     
  5. Offline

    OverDodo

    Worked!

    Thanks a lot! <3
     
  6. Offline

    Tecno_Wizard

    @OverDodo if you need more specific information in the future, JodaTime is probably your best bet.
     
Thread Status:
Not open for further replies.

Share This Page