트위터나 페이스북 등의 해외 서비스를 보면 글 등록 날짜를 실제 시간으로 표현하지 않고 "1일 전", "20시간 전" 등등으로 표현하는 경우가 많습니다. 그누보드에서도 날짜를 이런식으로 표현하는 방법입니다.
다음 코드를 head.sub.php에서 <!DOCTYPE html> 위쪽에 붙여넣으세요.
[code]
<?php
// 날짜 계산 함수
function passing_time($datetime) {
$time_lag = time() - strtotime($datetime);
if($time_lag < 60) {
$posting_time = "방금";
} elseif($time_lag >= 60 and $time_lag < 3600) {
$posting_time = floor($time_lag/60)."분 전";
} elseif($time_lag >= 3600 and $time_lag < 86400) {
$posting_time = floor($time_lag/3600)."시간 전";
} elseif($time_lag >= 86400 and $time_lag < 2419200) {
$posting_time = floor($time_lag/86400)."일 전";
} else {
$posting_time = date("y-m-d", strtotime($datetime));
}
return $posting_time;
}
?>
[/code]
이 함수는 다음과 같이 동작합니다.
1. 글을 쓴 지 60초 미만일 경우 - "방금"이라고 표기됩니다.
2. 글을 쓴 지 60초(1분) 이상 3600초(1시간) 미만일 경우 - "X분 전"이라고 표기됩니다.
3. 글을 쓴 지 3600초(1시간) 이상 86400초(1일) 미만일 경우 - "X시간 전"이라고 표기됩니다.
4. 글을 쓴 지 86400초(1일) 이상 2419200초(28일) 미만일 경우 - "X일 전"이라고 표기됩니다.
5. 글을 쓴지 28일 이상일 경우 - "년-월-일"이 표기됩니다.
불러 쓸 때는 다음과 같이 하면 됩니다.
게시판 목록(list.skin.php) :
<?php echo passing_time($list[$i]['wr_datetime']) ?>
게시판 내용 보기(view.skin.php) :
<?php echo passing_time($view['wr_datetime']) ?>
댓글 내용 보기(view_comment.skin.php) :
<?php echo passing_time($list[$i]['datetime']) ?>
다음 코드를 head.sub.php에서 <!DOCTYPE html> 위쪽에 붙여넣으세요.
[code]
<?php
// 날짜 계산 함수
function passing_time($datetime) {
$time_lag = time() - strtotime($datetime);
if($time_lag < 60) {
$posting_time = "방금";
} elseif($time_lag >= 60 and $time_lag < 3600) {
$posting_time = floor($time_lag/60)."분 전";
} elseif($time_lag >= 3600 and $time_lag < 86400) {
$posting_time = floor($time_lag/3600)."시간 전";
} elseif($time_lag >= 86400 and $time_lag < 2419200) {
$posting_time = floor($time_lag/86400)."일 전";
} else {
$posting_time = date("y-m-d", strtotime($datetime));
}
return $posting_time;
}
?>
[/code]
이 함수는 다음과 같이 동작합니다.
1. 글을 쓴 지 60초 미만일 경우 - "방금"이라고 표기됩니다.
2. 글을 쓴 지 60초(1분) 이상 3600초(1시간) 미만일 경우 - "X분 전"이라고 표기됩니다.
3. 글을 쓴 지 3600초(1시간) 이상 86400초(1일) 미만일 경우 - "X시간 전"이라고 표기됩니다.
4. 글을 쓴 지 86400초(1일) 이상 2419200초(28일) 미만일 경우 - "X일 전"이라고 표기됩니다.
5. 글을 쓴지 28일 이상일 경우 - "년-월-일"이 표기됩니다.
불러 쓸 때는 다음과 같이 하면 됩니다.
게시판 목록(list.skin.php) :
<?php echo passing_time($list[$i]['wr_datetime']) ?>
게시판 내용 보기(view.skin.php) :
<?php echo passing_time($view['wr_datetime']) ?>
댓글 내용 보기(view_comment.skin.php) :
<?php echo passing_time($list[$i]['datetime']) ?>
댓글 12개
와 2014년 글인데 아직도 문제없이 잘 되네요!
사용하는 테마의 head.sub.php에 넣고 쓰면 되고
혹시 x개월 전, x년 전 필요하신분 있으실 분 있으실것같아 그부분도 추가했어요
[code]
<?php
// 날짜 계산 함수
function passing_time($datetime) {
$time_lag = time() - strtotime($datetime);
if($time_lag < 60) {
$posting_time = "방금";
} elseif($time_lag >= 60 and $time_lag < 3600) {
$posting_time = floor($time_lag/60)."분 전";
} elseif($time_lag >= 3600 and $time_lag < 86400) {
$posting_time = floor($time_lag/3600)."시간 전";
} elseif($time_lag >= 86400 and $time_lag < 2592000) {
$posting_time = floor($time_lag/86400)."일 전";
} elseif($time_lag >= 2592000 and $time_lag < 31104000) {
$posting_time = floor($time_lag/2592000)."개월 전";
} elseif($time_lag >= 31104000 and $time_lag < 31536000) { //360일~365일 전의 기간에 작성된 게시글이 12개월전으로 표기되지 않게
$posting_time = "1년 전";
} else {
$posting_time = floor($time_lag/31536000)."년 전";
}
return $posting_time;
}
?>
[/code]
그 후에 써놓은대로 원하는 곳에서 출력하면 되네요
- list.skin.php
<?php echo passing_time($list[$i]['wr_datetime']) ?>
-view.skin.php
<?php echo passing_time($view['wr_datetime']) ?>
- view_comment.skin.php
<?php echo passing_time($list[$i]['datetime']) ?>
사용하는 테마의 head.sub.php에 넣고 쓰면 되고
혹시 x개월 전, x년 전 필요하신분 있으실 분 있으실것같아 그부분도 추가했어요
[code]
<?php
// 날짜 계산 함수
function passing_time($datetime) {
$time_lag = time() - strtotime($datetime);
if($time_lag < 60) {
$posting_time = "방금";
} elseif($time_lag >= 60 and $time_lag < 3600) {
$posting_time = floor($time_lag/60)."분 전";
} elseif($time_lag >= 3600 and $time_lag < 86400) {
$posting_time = floor($time_lag/3600)."시간 전";
} elseif($time_lag >= 86400 and $time_lag < 2592000) {
$posting_time = floor($time_lag/86400)."일 전";
} elseif($time_lag >= 2592000 and $time_lag < 31104000) {
$posting_time = floor($time_lag/2592000)."개월 전";
} elseif($time_lag >= 31104000 and $time_lag < 31536000) { //360일~365일 전의 기간에 작성된 게시글이 12개월전으로 표기되지 않게
$posting_time = "1년 전";
} else {
$posting_time = floor($time_lag/31536000)."년 전";
}
return $posting_time;
}
?>
[/code]
그 후에 써놓은대로 원하는 곳에서 출력하면 되네요
- list.skin.php
<?php echo passing_time($list[$i]['wr_datetime']) ?>
-view.skin.php
<?php echo passing_time($view['wr_datetime']) ?>
- view_comment.skin.php
<?php echo passing_time($list[$i]['datetime']) ?>
게시글 목록
| 번호 | 제목 |
|---|---|
| 1583 | |
| 1580 | |
| 1579 | |
| 1566 | |
| 1555 | |
| 1533 | |
| 1523 | |
| 1489 | |
| 1486 | |
| 1471 | |
| 1467 | |
| 1449 | |
| 1444 | |
| 1443 | |
| 1441 | |
| 1431 | |
| 1426 | |
| 1425 | |
| 1420 | |
| 1418 | |
| 1412 | |
| 1405 | |
| 1401 | |
| 1398 | |
| 1392 | |
| 1383 | |
| 1375 | |
| 1372 | |
| 1371 | |
| 1370 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기