함수 timeago()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:36 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
함수 agotime()
함수 timeago()
함수 snstime()
함수 relative_time()

1 JavaScript[ | ]

function timeago(date) {
	var t = new Date(date);
	var seconds = Math.floor((new Date() - t.getTime()) / 1000);
	if(seconds>86400) return t.toISOString().substring(0, 10);
	if(seconds>3600) return Math.floor(seconds/3600)+"시간전";
	if(seconds>60) return Math.floor(seconds/60)+"분전";
	return "방금";
}

2 PHP[ | ]

function timeago($str) {
	$t = strtotime($str);
	$seconds = time() - $t;
	if( $seconds>86400 ) return date('Y-m-d', $t);
	if( $seconds>3600 ) return ceil($seconds/3600).'시간전';
	if( $seconds>60 ) return ceil($seconds/60).'분전';
	return '방금';
}
echo \Carbon\Carbon::createFromTimeStamp(strtotime('2016-09-17 12:00'))->diffForHumans();
# 1 hour ago

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}