toString method

String toString()
override

Returns a string representation of the object in the format. "-d.hh:mm:ss.ff" where "-" is an optional sign for negative TimeSpan values, the "d" component is days, "hh" is hours, "mm" is minutes, "ss" is seconds, and "ff" is milliseconds

@return a string containing the number of milliseconds.

Implementation

String toString() {
  StringBuffer sb = new StringBuffer();
  int millis = this.time;
  if (millis < 0) {
    sb.write("-");
    millis = -millis;
  }

  int day = millis ~/ TimeSpan.DAYS;

  if (day != 0) {
    sb.write(day);
    sb.write("d.");
    millis = millis % TimeSpan.DAYS;
  }

  sb.write(millis / TimeSpan.HOURS);
  millis = millis % TimeSpan.HOURS;
  sb.write("h:");
  sb.write(millis / TimeSpan.MINUTES);
  millis = millis % TimeSpan.MINUTES;
  sb.write("m:");
  sb.write(millis / TimeSpan.SECONDS);
  sb.write("s");
  millis = millis % TimeSpan.SECONDS;
  if (millis != 0) {
    sb.write(".");
    sb.write(millis);
    sb.write("ms");
  }
  return sb.toString();
}