Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

hms.java

00001 package gov.nasa.arc.ase.util;
00002 
00003 public class hms {
00004   public static String format(long millisec) {
00005     StringBuffer value = new StringBuffer();
00006 
00007     long h = millisec / 3600000;
00008     long m = (millisec / 60000) % 60;
00009     long s = (millisec / 1000) % 60;
00010     long ms = millisec % 1000;
00011 
00012     if(h != 0) {
00013       value.append(h);
00014       value.append(':');
00015       format(value, m, 2);
00016       value.append(':');
00017       format(value, s, 2);
00018       value.append('.');
00019       format(value, ms, 3);
00020     } else if(m != 0) {
00021       value.append(m);
00022       value.append(':');
00023       format(value, s, 2);
00024       value.append('.');
00025       format(value, ms, 3);
00026     } else {
00027       value.append(s);
00028       value.append('.');
00029       format(value, ms, 3);
00030     }
00031 
00032     return value.toString();
00033   }  
00034   private static void format(StringBuffer sb, long v, int digits) {
00035     if(digits <= 1)
00036       sb.append(v);
00037     else {
00038       if(v < Math.pow(10, digits-1))
00039     sb.append('0');
00040       format(sb, v, digits-1);
00041     }
00042   }  
00043 }

Generated at Thu Feb 7 06:46:13 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001