public static String getFormatTime(long agoTime){
long nowTime = System.currentTimeMillis(); Calendar nowCalendar = Calendar.getInstance(); nowCalendar.setTimeInMillis(nowTime); Calendar agoCalendar = Calendar.getInstance(); nowCalendar.setTimeInMillis(agoTime); if ((agoCalendar.get(Calendar.YEAR) - nowCalendar.get(Calendar.YEAR)) > 0) { return (agoCalendar.get(Calendar.YEAR) - nowCalendar.get(Calendar.YEAR)) + "年前"; }else if((agoCalendar.get(Calendar.YEAR) - nowCalendar.get(Calendar.YEAR)) == 0) { if ((agoCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR)) >= 1 && (agoCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR)) <= agoCalendar.get(Calendar.DAY_OF_YEAR)) { return (agoCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR)) + "天前"; }else { if ((nowTime - agoTime) >= 3600000 && (nowTime - agoTime) < 3600000*24) { return (nowTime - agoTime)/3600000 + "小时前"; }else { if ((nowTime - agoTime)/60000 <= 60 && (nowTime - agoTime) >= 60000) { return (nowTime - agoTime)/60000 + "分钟前"; }else { return "刚刚"; } } } }else { return ""; } }
时间处理
最新推荐文章于 2023-03-06 18:34:29 发布