디지털 컨버전스/Project
[BoardProject] 날짜 표현
gimyeondong
2020. 5. 7. 10:27
DTO가 꼭 데이터베이스와 1:1 대응 되어야 하는 것 아니다.
저장소 이므로 필요한 데이터도 생성, 저장 가능
private String simpleDate;
public String getSimpleDate() {
long writer_date = this.writer_date.getTime(); //글 작성 시점
long current_date = System.currentTimeMillis(); //현재 시점
long gapTime = (current_date - writer_date)/1000 ;
if(gapTime < 60) {
return "방금 전";
}else if(gapTime < 300) {
return "5분 이내";
}else if(gapTime < 3600) {
return "1시간 이내";
}else if(gapTime < 86400) {
return "24시간 이내";
}else {
return simpleDate;
}
}
public BoardDTO(String seq, String title, String contents, String writer, String writer_date, String view_count,
String ip_addr) {
super();
this.seq = seq;
this.title = title;
this.contents = contents;
this.writer = writer;
this.write_date = write_date;
this.view_count = view_count;
this.ip_addr = ip_addr;
this.simpleDate = new SimpleDateFormat("YYYY-MM-dd").format(write_date);
}