I'm working on a IRC Twitch.tv BOT (PircBot) and i want to implement a !uptime chatcommand which will display how long the Stream is online.
I searched in google a Bit and i only found solutions which requires a GUI.
Can Some1 tell me what libraries are good to use or give me some exampel code?
I need to display seconds, minutes, hours, days.
First i thought about doing a normal timer which counts +1 all seconds but i think its easier and there are some proper functions to handle such "count"-timers, right?
Im fine with any hints!
thanks :)
Thats what i came up with now:
In my Main class, i got a timer which i call with:
utimecounttimer();
My Timer looks like this:
public void utimecounttimer() {
uptimetimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (isstreamlive == true){
UptimeCount.Uptimestart();
}else{
UptimeCount.Uptimestop();
}
}
}, 1000, 1000);
}
and then my UptimeCount Class is here:
public class UptimeCount {
public static long startTime = 0;
public static long OnlineTimeMillis = 0;
public static float OnlineTimeSec = 0;
public static float OnlineTimeMin = 0;
public static float OnlineTimeHour = 0;
public static float OnlineTimeDay = 0;
public static void Uptimestart(){
if(startTime == 0){
startTime = System.currentTimeMillis();
}else
if(startTime != 0){
OnlineTimeMillis = System.currentTimeMillis()-startTime;
OnlineTimeSec = OnlineTimeMillis /1000F;
OnlineTimeMin = OnlineTimeMillis /(60*1000F);
OnlineTimeHour = OnlineTimeMillis /(60*60*1000F);
OnlineTimeDay = OnlineTimeMillis /(24*60*60*1000F);
}
System.out.println("Seconds"+OnlineTimeSec);
System.out.println("Minutes"+OnlineTimeMin);
System.out.println("Hours"+OnlineTimeHour);
System.out.println("Days"+OnlineTimeDay);
}
public static void Uptimestop(){
startTime = 0;
OnlineTimeMillis = 0;
OnlineTimeSec = 0;
OnlineTimeMin = 0;
OnlineTimeHour = 0;
OnlineTimeDay = 0;
}
}
And then, last but not least il get the Infos in chat with the following line in my Main class:
if (message.equalsIgnoreCase("!uptime")) {
sendMessage(channel," Stream is running for: "+UptimeCount.OnlineTimeDay +" Days, "+UptimeCount.OnlineTimeHour +" Hours. "+UptimeCount.OnlineTimeMin +" Minutes and " +UptimeCount.OnlineTimeSec +" Seconds.");
}
I didnt test it yet but i think i have to format the ms output of the floats and then it should be working, right?