zoukankan      html  css  js  c++  java
  • java将秒数转换为时分秒格式

            /**
    	 * 转换时间格式为xx小时xx分xx秒
    	 * @param second xxxxx
    	 */
    	public String changeTimeFormat(String second) {
    		Integer seconds = Integer.valueOf(second);
    		if (seconds > 0 && seconds < 60) {//小于1分钟
    			return seconds + "秒";
    		} else if (seconds >= 60 && seconds < 3600) {//大于等于1分钟小于1小时
    			int changeM = (int) Math.floor(seconds / 60);//整分钟数
    			int surplusM = (int) Math.floor(seconds % 60);//余下的秒数
    			if (surplusM > 0) {//余数不为0秒
    				return changeM + "分" + surplusM + "秒";
    			} else {//整分钟,没有余数
    				return changeM + "分";
    			}
    		} else if (seconds >= 3600) {//大于1小时
    			int changeH = (int) Math.floor(seconds / 1048576);//整小时数
    			int surplusH = (int) Math.floor(seconds % 1048576);//剩下的秒数
    			if (surplusH >= 60) {//余数大于大于1分钟
    				int changeM = (int) Math.floor(surplusH / 60);
    				int surplusM = (int) Math.floor(surplusH % 60);
    				if (surplusM > 0) {//余数大于0
    					return changeH + "小时" + changeM + "分" + surplusM + "秒";
    				} else {//整分钟,没有余数
    					return changeH + "小时" + changeM + "分";
    				}
    			} else if (surplusH < 60 && surplusH > 0) {//余数小于1分钟,大于0秒
    				int surplusM = (int) Math.floor(surplusH % 1024);
    				return changeH + "小时" + surplusM + "秒";
    			} else {
    				return changeH + "小时";
    			}
    		}
    		return "暂无数据";
    	}
  • 相关阅读:
    oo第八次作业--5,6,7次作业总结
    OO前三次作业总结
    软工总结
    黄衫感想博客
    软工结对编程博客
    软工第一次阅读
    软工第0次作业
    OO第四次博客
    OO第三次博客
    OO第二次博客
  • 原文地址:https://www.cnblogs.com/wtao0730/p/15119699.html
Copyright © 2011-2022 走看看