전체최신글에서 코멘트(댓글) 시간표기하는 방법을 문의합니다
본문
안녕하세요?
보들이윤님이 알려주신 방법인데...보들이윤님~ 죄송합니다.
제가 적용을 잘못해서인지 자정이 넘어가도 글쓴 후 24시간 이내에는 '몇 시간 전' 이렇게 출력이 되어야 하는데
자정이 넘어가니까 글쓴 후 24시간 이내인데도 '2017-01-24' 이렇게 날짜로 출력이 되어버리네요~
if($list[$i][wr_comment] >= date("Y-m-d H:i:s", G5_SERVER_TIME - (24 * 3600))) // 코멘트가 24시간 이내이면
echo $list[$i]['datetime3'];
elseif($list[$i][wr_comment] < date("Y-m-d H:i:s", G5_SERVER_TIME - (24 * 3600))) // 코멘트가 24시간 이후이면
echo $list[$i]['datetime3'];
else
echo $list[$i]['datetime3'];
전체최신글에서 원글 리스트는 자정이 넘어가도 글쓴 후 24시간 이내에는 '몇 시간 전' 이렇게 출력이 되는데
코멘트(댓글) 리스트만 글쓴 후 24시간 이내인데도 '2017-01-24' 이렇게 날짜로 출력이 됩니다.
참! 어렵네요~
짜집퍼라...보름 정도 이리저리해도 해결을 못하고 있습니다...ㅜㅜ
새해 복 많이 받으시고 항상 건강하십시오~^^)
감사합니다.
답변 2
조건이 잘못된듯합니다.
if($list[$i][wr_comment] >= date("Y-m-d H:i:s", G5_SERVER_TIME - (24 * 3600)))
$list[$i][wr_comment] 는 시간이 들어있는것이아니라
숫자 0,1,2,3등 코멘트의 갯수가 들어가는 필드이고
if 조건문에서 시간을 비교하는데
시간과 시간을 비교하는것이 아니기때문에 무조건 else가 됩니다.
$list[$i][wr_comment]를
$list[$i][wr_last]로 바꾸어보세요
function date_sns($wr_datetime){
global $g4;
$timestamp = strtotime($wr_datetime); // 글쓴날짜시간 Unix timestamp 형식
$current = $g4['server_time']; // 현재날짜시간 Unix timestamp 형식
// 1년전
if($timestamp > $current - 86400){
if ($timestamp <= $current - 86400) {
$str = "어제";
}
else if ($timestamp <= $current - 3600 * 1) {
$str = (int)(($current - $timestamp) / 3600) . "시간전";
}
else if ($timestamp <= $current - 60 * 1) {
$str = (int)(($current - $timestamp) / 60) . "분전";
}
else {
$str = (int)($current - $timestamp) . "초전";
}
$list['datetime2'] = $str;
}else{
$list['datetime'] = substr($wr_datetime,0,10);
$list['datetime2'] = $wr_datetime;
if ($list['datetime'] == $g4['time_ymd'])
$list['datetime2'] = substr($list['datetime2'],11,5);
else if (substr($list['datetime'],0,4) == substr($g4['time_ymd'],0,4))
$list['datetime2'] = substr($list['datetime2'],5,5);
else if (days_diff($list['datetime']) <= 60)
$list['datetime2'] = substr($list['datetime2'],5,5);
else
$list['datetime2'] = substr($list['datetime2'],0,7);
}
return $list['datetime2'];
}