java 幾分鍾前,幾小時前


SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
String createDate = null;
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createTime = sdf2.format(gcCommentList.get(i).getCreateTime());
Date date = null;
try {
date = sdf2.parse(createTime);
long differenceValue = new Date().getTime() - date.getTime();
if(differenceValue < 3600000){
if((differenceValue / 1000 / 60 )==0){
createDate = "剛剛";
}else{
createDate = (differenceValue / 1000 / 60 ) + "分鍾前";
}

}else if(differenceValue > 3600000){
if(differenceValue < 86400000){
createDate = (differenceValue / 1000 / 60 / 60 ) + "小時前";
}else{
createDate = sdf.format(gcCommentList.get(i).getCreateTime());
}
}
paramMap.put("createTime", createDate);
} catch (ParseException e) {
e.printStackTrace();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM