时间差 转换成天时分秒
public class 时间转换天时分秒 { public static void main(String[] args) { //时间差 long timeDifference=12313213; System.out.println(conversion(timeDifference)); } //分 private static Integer branch=60; //时 private static Integer time=60*60; /** * 天 */ private static Integer days= 60*60*24; private static String conversion(long timeDifference) { //转换 String timedesc=null; long minutes; long remainingSeconds; long hour; long day; if (timeDifference<branch){ timedesc=(timeDifference)+"秒"; }else if (timeDifference>branch-1&&timeDifference<time){ minutes = timeDifference / branch; remainingSeconds= timeDifference % branch; timedesc= minutes +"分"+remainingSeconds+"秒"; }else if (timeDifference>time-1&&timeDifference<days){ hour=timeDifference/time; remainingSeconds = (timeDifference%time)/branch; minutes = (timeDifference%days)%branch; timedesc=hour+"时"+minutes +"分"+remainingSeconds+"秒"; }else if(timeDifference>days-1){ day= timeDifference/ ( days); hour = (timeDifference% ( days)) / (time); minutes = (timeDifference % (time)) /branch; remainingSeconds = timeDifference % branch; timedesc=day+"天"+hour+"时"+minutes +"分"+remainingSeconds+"秒"; } return timedesc; } }
示例: