1. 程式人生 > >毫秒轉成時分秒

毫秒轉成時分秒

/**
	 * 把毫秒數轉換成時分秒
	 * @param millis
	 * @return
	 */
	public static String millisToStringShort(long millis) {
		StrBuilder strBuilder = new StrBuilder();
		long temp = millis;
		long hper = 60 * 60 * 1000;
		long mper = 60 * 1000;
		long sper = 1000;
		if (temp / hper > 0) {
			strBuilder.append(temp / hper).append("小時");
		}
		temp = temp % hper;

		if (temp / mper > 0) {
			strBuilder.append(temp / mper).append("分鐘");
		}
		temp = temp % mper;
		if (temp / sper > 0) {
			strBuilder.append(temp / sper).append("秒");
		}
		return strBuilder.toString();
	}