package com.lcjian.library.util.common;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
public class TimeUtil {
|
|
/**
|
* 将秒转换为形如01:12这种形式
|
*
|
* @param seconds
|
* @return
|
*/
|
public static String getTimeDesc(int seconds) {
|
if (seconds <= 0)
|
return "00:00";
|
|
int h = seconds / 3600;
|
int m = (seconds - h * 3600) / 60;
|
int s = seconds % 60;
|
String str = "";
|
if (s < 10)
|
str += "0" + s;
|
else
|
str += s;
|
if (m == 0)
|
str = "00:" + str;
|
else if (m < 10)
|
str = "0" + m + ":" + str;
|
else
|
str = m + ":" + str;
|
if (h > 0) {
|
if (h < 10)
|
str = "0" + h + ":" + str;
|
else
|
str = h + ":" + str;
|
}
|
return str;
|
}
|
|
|
public static String getGeneralTime(long timeStamp, String template) {
|
SimpleDateFormat sdf = new SimpleDateFormat(template);
|
String date = sdf.format(new Date(timeStamp));
|
return date;
|
}
|
|
}
|