public class Time {
public static String formatDateTime(long mss) {
String DateTimes = null;
long days = mss / ( 60 * 60 * 24);
long hours = (mss % ( 60 * 60 * 24)) / (60 * 60);
long minutes = (mss % ( 60 * 60)) /60;
long seconds = mss % 60;
if(days>0){
DateTimes= days + "天" + hours + "小时" + minutes + "分钟"
+ seconds + "秒";
}else if(hours>0){
DateTimes=hours + "小时" + minutes + "分钟"
+ seconds + "秒";
}else if(minutes>0){
DateTimes=minutes + "分钟"
+ seconds + "秒";
}else{
DateTimes=seconds + "秒";
}
return DateTimes;
}
}
public static String formatDateTime(long mss) {
String DateTimes = null;
long days = mss / ( 60 * 60 * 24);
long hours = (mss % ( 60 * 60 * 24)) / (60 * 60);
long minutes = (mss % ( 60 * 60)) /60;
long seconds = mss % 60;
if(days>0){
DateTimes= days + "天" + hours + "小时" + minutes + "分钟"
+ seconds + "秒";
}else if(hours>0){
DateTimes=hours + "小时" + minutes + "分钟"
+ seconds + "秒";
}else if(minutes>0){
DateTimes=minutes + "分钟"
+ seconds + "秒";
}else{
DateTimes=seconds + "秒";
}
return DateTimes;
}
}
本文介绍了一个简单的Java程序,该程序能够将毫秒数转换为更易读的时间格式,如天、小时、分钟和秒。根据毫秒数的不同,程序会智能地选择合适的时间单位组合进行显示。
2325

被折叠的 条评论
为什么被折叠?



