java将分钟转成时分将秒时间转换

版权声明: https://blog.csdn.net/qq_36421955/article/details/88749653

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 void main(String[] args) {
long mss=17551;
String ss= Time.formatDateTime(mss);
System.out.println(ss);
}
}

猜你喜欢

转载自blog.csdn.net/qq_36421955/article/details/88749653
今日推荐