/** * Time Conversion Tool class * @author Lin LI * @DATE 2015-08-26 */public class test {public static void main (String[] args) {// Conversion format: Days-hours-minutes-seconds sectime (60*60); // incoming unit seconds// conversion format: Days-hours-minutes-seconds-milliseconds difftime (2800); // Incoming units MS}/** * conversion format: Days-hours-minutes-seconds * @param sectime */public static void sectime (long sectime) {long nd = 24*60*60;//seconds per day long nh = 60*60;// The number of seconds in an hour long nm = 60;//the number of seconds in a minute long day = sectime/nd;//calculate how many days long hour = sectime%nd/nh;//calculate how many hours long min = sectime%nd%nh/nm;//calculate how many minutes long sec = sectime%nd%nh%nm;//calculates how many seconds System.out.println (day+ "Days" +hour+ "hours" +min+ "minutes" +sec+ "seconds. ");} /** * conversion Format: Days-hours-minutes-Sec-msec * @param diff */public static void difftime (Long difftime) {long nd = 1000*24*60*60;//the number of milliseconds in a daylong nh = 1000*60*60;//the number of milliseconds in an hour long nm = 1000*60;//the number of milliseconds in a minute long ns = 1000;//the number of milliseconds in a second longlong day = difftime/nd;//calculate the difference in how many days long hour = difftime%nd/ nh;//Calculate the difference in how many hours long min = difftime%nd%nh/nm;//calculate the difference in how many minutes long sec = difftime%nd%nh%nm/ ns;//Calculate the difference in how many seconds System.out.println (day+ "Day" +hour+ "Hour" +min+ "minutes" +sec+ "seconds");}}
Time Conversion Tool Class