赞
踩
// 转换为时分秒
public String formatTimeHMS(long time) {
return new SimpleDateFormat("HH:mm:ss").format(time);
}
// 转换为年月日
public static String formatTimeYMD(long time) {
return new SimpleDateFormat("yyyy-MM-dd").format(time);
}
// 转换为年月日时分秒毫秒
public static String formatTimeYMDHMSSSS(long time) {
return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(time);
}
// 转换为年-月-日 时:分:秒:毫秒
public static String formatTimeYMD_HMS_SSS(long time) {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(time);
}
// 获取past天前的日期
public String getPastDate(int past) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
Date today = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
return format.format(today);
}
public static String formatTime(Long ms) {
int ss = 1000;
int mi = ss * 60;
Integer hh = mi * 60;
Integer dd = hh * 24;
Long day = ms / dd;
Long hour = (ms - day * dd) / hh;
long minute = (ms - day * dd - hour * hh) / mi;
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
StringBuilder sb = new StringBuilder();
if(day > 0) {
sb.append(day).append("天");
}
if(hour > 0) {
sb.append(hour).append("小时");
}
if(minute > 0) {
sb.append(minute).append("分");
}
if(second > 0) {
sb.append(second).append("秒");
}
if(milliSecond > 0) {
sb.append(milliSecond).append("毫秒");
}
return sb.toString();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。