PHP 시간표시를 SNS형식으로 출력하기 > 자료실

회원로그인

오늘 본 게시물

오늘 본 페이지

없음

오늘 본 C.m.A Util

없음

자료실

자료실

PHP 시간표시를 SNS형식으로 출력하기

페이지 정보

본문


function display_datetime($datetime = '') {
	if (empty($datetime)) {
		return false;
	}

	$diff = time() - strtotime($datetime);
	$s = 60; //1분 = 60초
	$h = $s * 60; //1시간 = 60분
	$d = $h * 24; //1일 = 24시간
	$y = $d * 10; //1년 = 1일 * 10일

	if ($diff < $s) {
		$result = $diff . '초전';
	} elseif ($h > $diff && $diff >= $s) {
		$result = round($diff/$s) . '분전';
	} elseif ($d > $diff && $diff >= $h) {
		$result = round($diff/$h) . '시간전';
	} elseif ($y > $diff && $diff >= $d) {
		$result = round($diff/$d) . '일전';
	} else {
		$result = date('Y.m.d.', strtotime($datetime));
	}
	return $result;

}

public function short_get_time($wdate=''){ if ( !$wdate ) : return '방금'; endif; $time = time()-strtotime($wdate); if (!$time ) : return '방금'; endif; $stat = ' 전'; if ( $time < 0 ) : $time*=-1; $stat = ' 후'; endif; // $time=abs($time); $ago = array(); if( $time < 172800 ) : //$ct = array(31536000,2592000,604800,86400,3600,60,1); // 대략(년:365일,월:30일 기준) //$tt = array('년','달','주','일','시간','분','초'); $ct = array(86400,3600,60,1); // 대략(년:365일,월:30일 기준) $tt = array('일','시간','분','초'); foreach ( $ct AS $k => $v ) : if ( $n=floor($time/$v) ) : $ago[] = $n.$tt[$k]; $time-=$n*$v; endif; endforeach; return implode(' ',array_slice($ago,0,1)).$stat; else : $con_wate = date("m", strtotime($wdate))."월 ".date("d", strtotime($wdate))."일" ; return $con_wate; endif; }



추천 0 비추천 0

  • 회사 : Cginjs
  • 대표 : Cginjs
  • 주소 :
  • 메일 : admin@mysample.com
  • 사업자 등록번호 :
Copyright © Cginjs All rights reserved.
notice
Warning: Undefined variable $HTTP_ACCEPT_LANGUAGE in /cginjs/www/bbs/visit_insert.inc.php on line 131