DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005

    Question printing how long the file has been running

    I make bots for this game called Continuum. I'm still pretty new. I looked around almost everywhere and couldn't find any code that would help me display how long the bot has been up.

    I need it to say something like "2 day(s) 11 hour(s) 33 minute(s) [09/18/2005]"

    Can you please help me out?

    Oh and please post some code.

  2. #2
    Join Date
    Nov 2004

    What have you got ?

    I assume you have the duration time and just wants to display this and
    the current date ?
    import java.util.*;
    import java.text.*;
     * Display elapsed time (from milliseconds) and current date.
    public class TimeDisplay {
      static SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
      public TimeDisplay() {}
       * @param duration, the elapsed time in milliseconds
      public String getTimeString(long duration) {
        Date today=new Date(System.currentTimeMillis());
        String dateStr=df.format(today);
        String durationStr=getStringTime(duration);
        return durationStr+"["+dateStr+"]";
       * Convert a millisec time into days, hours and minutes
       * @param t
       * @return
      private String getStringTime(long t) {
        t /= 1000; // make seconds
        long days=t/(3600*24);
        t -= days*(3600*24);
        long hrs=t/3600;
        t -= hrs*3600;
        long min=t/60;
        String s="";
        if (days > 0) {
          s += days+" day(s) ";
        if (hrs > 0) {
          s += hrs +" hours(s) ";
        if (min > 0) {
          s += min +" minute(s) ";
        return s;
      public static void main (String [] args) {
        TimeDisplay td=new TimeDisplay();
        String s=td.getTimeString(300000034);
    eschew obfuscation

  3. #3
    Join Date
    Sep 2005
    Well i don't have the duration time.

    I want to be able to get it, like if the duration was 5000ms it would say:

    Bot up for: 0 day(s) 0 hour(s) 5 second(s).

    So basically i guess im looking for the duration time. I tried the code you gave me, i tried putting it into my bot but it won't work.

    I need something that will do something like this.
    public void btime(String name, String msg){
    //Get the duration time here.
    m_botAction.sendPrivateMessage( name, time );
    but also i would need the milliseconds seperated into days,hours,minutes, and seconds.


  4. #4
    Join Date
    Nov 2004
    Without the duration time there is very little to do with this problem, there is no magic
    in my code that could find that value, and the code worked when I posted it.

    If you have the complete source code for the game you should be able to implement
    a bot timer yourself. As I understand it the bot is a class, so you could just
    introduce a long variable called startTime that is set on bot startup, or...
    eschew obfuscation

Similar Threads

  1. Removing System Tray shortcuts
    By James Brown in forum VB Classic
    Replies: 8
    Last Post: 03-05-2002, 12:54 PM
  2. Change NT service config (disabled -> enabled)
    By pavel in forum VB Classic
    Replies: 0
    Last Post: 10-17-2001, 08:06 PM
  3. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 06:24 PM
  4. Getting remote registry entries
    By Pedro Avila in forum VB Classic
    Replies: 4
    Last Post: 04-02-2001, 11:31 AM
  5. Adding New NT User Account
    By John Whitney in forum VB Classic
    Replies: 2
    Last Post: 02-01-2001, 11:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.