반응형
두 시간을 비교하여 경과 시간 표시 (페이스북 몇분 전에 쓴글 표시)
public String diffOfDate(Date begin) throws Exception
{
Date endDate = new Date();
long diffDays;
String elapsetime="";
long diff = endDate.getTime() - begin.getTime();
diff= diff/1000;
if(86400<diff){
diffDays = diff / (24 * 60 * 60);
elapsetime=diffDays+"일 전";
}else if(86400>diff){
diffDays = diff / (60 * 60);
elapsetime=diffDays+"시간 전";
}else if(60<=diff){
diffDays = diff / (60);
elapsetime=diffDays+"분 전";
}else if(60>diff){
elapsetime=diff+"초 전";
}
return elapsetime;
}
반응형
댓글