함수 timeago()

함수 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 }})
{{ zf.userName }}
{{ comment.name }} {{ comment.created | snstime }}