Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function to return a string in java
  2. public String time_to_string(long t) // time in milliseconds
  3. {
  4.     String ans;
  5.     int mins,secs;
  6.     if (t < 0)
  7.     {
  8.         return "-";
  9.     }
  10.     else
  11.     {
  12.         secs = (int)(t/1000);
  13.         mins = secs/60;
  14.         secs = secs - (mins * 60);
  15.  
  16.         ans = ""+mins+":"+String.format("%02d", secs);
  17.  
  18.         return ans;
  19.     }
  20. }
  21.        
  22. public String time_to_string(long t) // time in milliseconds
  23. {
  24.     if (t < 0)
  25.     {
  26.         return "-";
  27.     }
  28.     else
  29.     {
  30.         int secs = (int)(t/1000);
  31.         int mins = secs/60;
  32.         secs = secs - (mins * 60);
  33.         return String.format("%d:%02d", mins, secs);
  34.     }
  35. }
  36.        
  37. return String.format("%d:%d", mins, secs);