1 18 package net.sf.drftpd.util; 19 20 24 public class Time { 25 28 public static String formatTime(long millis) { 29 long days = 0, hours = 0, mins = 0, secs = 0; 30 String time = ""; 31 32 secs = millis / 1000; 33 34 while ( secs >= 86400) { 35 days++; 36 secs -= 86400; 37 } 38 while ( secs >= 3600 ) { 39 hours++; 40 secs -= 3600; 41 } 42 while ( secs >= 60 ) { 43 mins++; 44 secs -= 60; 45 } 46 if ( days != 0 ) time = days + "days "; 47 if ( hours != 0 ) time = hours + "h "; 48 if ( mins != 0 ) time += mins + "m "; 49 time += secs + "s"; 50 51 return time; 52 } 53 public static long parseTime(String s) { 54 s=s.toLowerCase(); 55 if(s.endsWith("ms")) { 56 return Long.parseLong(s.substring(0, s.length()-2)); 57 } 58 if (s.endsWith("s")) { 59 return Long.parseLong(s.substring(0, s.length()-1))*1000; 60 } 61 if(s.endsWith("m")) { 62 return Long.parseLong(s.substring(0, s.length()-1))*60000; 63 } 64 return Long.parseLong(s); 65 } 66 } | Popular Tags |