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.

Hh:mm:ss Run Time Method?

Featured Replies

Hey Guys,

 

Anyone help me out back to scripting after a few years and have forgotten a few things.

 

How do I get my run time in HH:MM:SS, atm it's like 23742384.

 

Cheers.

Well you could use a stringbuilder but probably easier to use a date formatter 

                Date date = new Date(System.currentTimeMillis() - startTime);
		DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
		String dateFormatted = formatter.format(date);

Where startTime is a variable defined as:

	long startTime = System.currentTimeMillis();

Hope I helped

Apaec

 

 

Edit: As I was saying before, here's an example of a timeformatter using a stringbuilder:

public static String timeFormat(long time) {
		StringBuilder t = new StringBuilder();
		long total_secs = time / 1000L;
		long total_mins = total_secs / 60L;
		long total_hrs = total_mins / 60L;
		long total_days = total_hrs / 24L;
		int secs = (int) total_secs % 60;
		int mins = (int) total_mins % 60;
		int hrs = (int) total_hrs % 24;
		int days = (int) total_days;
		if (days < 10) {
			t.append("0");
		}
		t.append(days).append(":");
		if (hrs < 10) {
			t.append("0");
		}
		t.append(hrs).append(":");
		if (mins < 10) {
			t.append("0");
		}
		t.append(mins).append(":");
		if (secs < 10) {
			t.append("0");
		}
		t.append(secs);
		return t.toString();
	}

Hey Guys,

 

Anyone help me out back to scripting after a few years and have forgotten a few things.

 

How do I get my run time in HH:MM:SS, atm it's like 23742384.

 

Cheers.

 

Edited by Apaec

I think I took this from a scripter a while back so no credit of my own:

 

function for formatting time string.

	public String format(long time) {
		StringBuilder string = new StringBuilder();
		long totalSeconds = time / 1000L;
		long totalMinutes = totalSeconds / 60L;
		long totalHours = totalMinutes / 60L;
		int seconds = (int) totalSeconds % 60;
		int minutes = (int) totalMinutes % 60;
		int hours = (int) totalHours % 24;
		if (hours > 0) {
			string.append((new StringBuilder(String.valueOf(hours))).append(
					":").toString());
		}
		if (minutes > 0) {
			string.append((new StringBuilder(String.valueOf(minutes))).append(
					":").toString());
		}
		string.append((new StringBuilder(String.valueOf(seconds))).append(":")
				.toString());
		return string.toString();
	}

onStart function:

	@Override
	public void onStart() {
		startTime = System.currentTimeMillis();
	}

onPaint function:

	public void onPaint(Graphics2D g) {
		long elapsed = System.currentTimeMillis() - startTime;
		g.drawString((new StringBuilder("Time: ")).append(format(elapsed)).toString(), 50, 50);
	}

 

Well you could use a stringbuilder but probably easier to use a date formatter 

                Date date = new Date(System.currentTimeMillis() - startTime);
		DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
		String dateFormatted = formatter.format(date);

Where startTime is a variable defined as:

	long startTime = System.currentTimeMillis();

Hope I helped

Apaec

 

 

Edit: As I was saying before, here's an example of a timeformatter using a stringbuilder:

public static String timeFormat(long time) {
		StringBuilder t = new StringBuilder();
		long total_secs = time / 1000L;
		long total_mins = total_secs / 60L;
		long total_hrs = total_mins / 60L;
		long total_days = total_hrs / 24L;
		int secs = (int) total_secs % 60;
		int mins = (int) total_mins % 60;
		int hrs = (int) total_hrs % 24;
		int days = (int) total_days;
		if (days < 10) {
			t.append("0");
		}
		t.append(days).append(":");
		if (hrs < 10) {
			t.append("0");
		}
		t.append(hrs).append(":");
		if (mins < 10) {
			t.append("0");
		}
		t.append(mins).append(":");
		if (secs < 10) {
			t.append("0");
		}
		t.append(secs);
		return t.toString();
	}

pls no

DateFormat

BAD

 

Could have at least trimmed down the quote to show that. Also could have elaborated a lot more...

Could have at least trimmed down the quote to show that. Also could have elaborated a lot more...

 

Also he coulda helped instead of critisizing other people helping

Edited by Apaec

  • Author
public static String timeFormat(long time) {
		StringBuilder t = new StringBuilder();
		long total_secs = time / 1000L;
		long total_mins = total_secs / 60L;
		long total_hrs = total_mins / 60L;
		long total_days = total_hrs / 24L;
		int secs = (int) total_secs % 60;
		int mins = (int) total_mins % 60;
		int hrs = (int) total_hrs % 24;
		int days = (int) total_days;
		if (days < 10) {
			t.append("0");
		}
		t.append(days).append(":");
		if (hrs < 10) {
			t.append("0");
		}
		t.append(hrs).append(":");
		if (mins < 10) {
			t.append("0");
		}
		t.append(mins).append(":");
		if (secs < 10) {
			t.append("0");
		}
		t.append(secs);
		return t.toString();
	}

I'm using this method, but it's only showing H:MM:SS. How can I change it to HH:MM:SS?

 

I've tried numerous things and can't figure it out :X

Could have at least trimmed down the quote to show that. Also could have elaborated a lot more...

Also he coulda helped instead of critisizing other people helping

read the jdocs for SimpleDataFormat#format and you'll see why. and the other method was just ugly 

  • Author

read the jdocs for SimpleDataFormat#format and you'll see why. and the other method was just ugly 

Got a link to the JavaDoc?

Don't make things so complicated.

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

Edited by Czar

Don't make things so complicated.

public String formatTime(final long time) {final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s);}
And this is why I need scripting friends that are better than me. Beautiful code!
public static String timeFormat(long time) {
		StringBuilder t = new StringBuilder();
		long total_secs = time / 1000L;
		long total_mins = total_secs / 60L;
		long total_hrs = total_mins / 60L;
		long total_days = total_hrs / 24L;
		int secs = (int) total_secs % 60;
		int mins = (int) total_mins % 60;
		int hrs = (int) total_hrs % 24;
		int days = (int) total_days;
		if (days < 10) {
			t.append("0");
		}
		t.append(days).append(":");
		if (hrs < 10) {
			t.append("0");
		}
		t.append(hrs).append(":");
		if (mins < 10) {
			t.append("0");
		}
		t.append(mins).append(":");
		if (secs < 10) {
			t.append("0");
		}
		t.append(secs);
		return t.toString();
	}

 

Don't make things so complicated.

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

This is the same thing as above but even worse.

 

I really don't see why people insist on making their code unreadable just because "it saves lines". I know the ternary is actually slower in C# when compared to nested if statements because of the JIT trying to make optimizations, not sure about Java.

Edited by Swizzbeat

Guest
This topic is now closed to further replies.

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.