SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a",Locale.ENGLISH);
Date d2 = null;
try {
d2 = sdf.parse("Sep 18, 2017 4:17:28 PM");
} catch (ParseException e) {
e.printStackTrace();
}
Date d3 = new Date();
LogUtil.e("d2 ====== "+d2+" "+sdf2.format(d2));
LogUtil.e("d3 ====== "+" "+d3+" "+sdf.format(d3));
/**
* 根据时间 转换格式
*
* @param lSeconds
* @return
*/
public static String formatTimeString(long lSeconds) {
long nHour = lSeconds / 3600;
long nMin = lSeconds % 3600;
long nSec = nMin % 60;
nMin = nMin / 60;
if (nHour != 0 && nMin != 0 && nSec != 0) {
return String.format("%02d小时%02d分钟%02d秒", nHour, nMin, nSec);
} else if (nHour != 0 && nMin == 0 && nSec == 0) {
return String.format("%02d小时", nHour);
} else if (nHour == 0 && nMin != 0 && nSec != 0) {
return String.format("%02d分钟%02d秒", nMin, nSec);
} else if (nHour == 0 && nMin != 0) {
return String.format("%02d分钟", nMin);
} else if (nHour == 0 && nSec != 0) {
return String.format("%02d秒", nSec);
}
return String.format("%02d小时%02d分钟%02d秒", nHour, nMin, nSec);
}
/***
* 格式化时间
* @param pattern
* @param milli
* @return
*/
public static String formatTime(String pattern, int milli) {
int h = (int) (milli / DateUtils.HOUR_IN_MILLIS);
int m = (int) (milli / DateUtils.MINUTE_IN_MILLIS);
int s = (int) ((milli / DateUtils.SECOND_IN_MILLIS) % 60);
String hh = String.format(Locale.getDefault(), "%02d", h);
String mm = String.format(Locale.getDefault(), "%02d", m);
String ss = String.format(Locale.getDefault(), "%02d", s);
return pattern.replace("hh", hh).replace("mm", mm).replace("ss", ss);
}