Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Formatting time to 00:00:00:00

Featured Replies

	public static String formatTimeDHMS(final long time) {
		final int sec = (int) (time / 1000), d = sec / 86400, h = sec / 3600 % 24, m = sec / 60 % 60, s = sec % 60;
		return (d < 10 ? "0" + d : d) + ":" + (h < 10 ? "0" + h : h) + ":"
				+ (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s);
	}

where time is in milliseconds.

 

Implementation:

g.drawString("Runtime: " + formatTimeDHMS(timer.getElapsed()), 100,100);

where g = graphics2d

and timer is your timer from the start of the script

and getelapsed is a method from your timer class returning the time elapsed in millis

 

This ill be formatted as: 00:00:00:00.

                                        d: h: m: s

 

Apa

How about 

 

Class:

 public class Timer {

        private Instant start;

        private static final String formatter = "%02d";

        public Timer() {
            reset();
        }

        public void reset() {
            start = Instant.now();
        }

        public Duration duration() {
            return Duration.between(start, Instant.now());
        }

        @Override
        public String toString() {
            Duration duration = duration();
            return String.format(formatter, duration.toHours()) + " : " + String.format(formatter, duration.toMinutes() % 60) + " : " + String.format(formatter, duration.getSeconds() % 60);
        }

    }

Setup:

 Timer t = new Timer();

Usage:

  g.drawString("Time: " + t.toString(), 55, 401);
  • Author

 

How about 

 

Class:

 public class Timer {

        private Instant start;

        private static final String formatter = "%02d";

        public Timer() {
            reset();
        }

        public void reset() {
            start = Instant.now();
        }

        public Duration duration() {
            return Duration.between(start, Instant.now());
        }

        @Override
        public String toString() {
            Duration duration = duration();
            return String.format(formatter, duration.toHours()) + " : " + String.format(formatter, duration.toMinutes() % 60) + " : " + String.format(formatter, duration.getSeconds() % 60);
        }

    }

Setup:

 Timer t = new Timer();

Usage:

  g.drawString("Time: " + t.toString(), 55, 401);

 

That works too

i have my method also built into my timer class

 

I dislike java's duration and instant classes tho. 

 

your method does not format days though, but that would be easy to add.

 

apa

That works too

i have my method also built into my timer class

 

I dislike java's duration and instant classes tho. 

 

your method does not format days though, but that would be easy to add.

 

apa

 

Ah yes yes, think I will add that in now. biggrin.png

 

Guess i will add:

  return String.format(formatter, duration.toDays()) + " : " +  String.format(formatter, duration.toHours()) + " : " + String.format(formatter, duration.toMinutes() % 60) + " : " + String.format(formatter, duration.getSeconds() % 60);

Edited by Dark Magician

in timer class

 public static String format(long milliSeconds)
   {
       long secs = milliSeconds / 1000L;
       return String.format("%02d:%02d:%02d:%02d", new Object[] {
       Long.valueOf(milliSeconds / (1000*60*60*24)) , Long.valueOf((secs / 3600L) % 24), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
       });
   }

in main 

final long lngStartTime = System.currentTimeMillis(); 

on paint

 g.drawString(""+Timer.format(System.currentTimeMillis() - lngStartTime), X, Y)
  • Author

 

in timer class

 public static String format(long milliSeconds)
   {
       long secs = milliSeconds / 1000L;
       return String.format("%02d:%02d:%02d:%02d", new Object[] {
       Long.valueOf(milliSeconds / (1000*60*60*24)) , Long.valueOf((secs / 3600L) % 24), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
       });
   }

in main 

final long lngStartTime = System.currentTimeMillis(); 

on paint

 g.drawString(""+Timer.format(System.currentTimeMillis() - lngStartTime), X, Y)

 

Defining your start time at the top of your code as you have suggested is a risky thing to do - it can sometimes return unexpected results

apa :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.