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

자료실

자료실

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

페이지 정보

profile_image
작성자 최고관리자
댓글 0 조회 339회 작성일 23-03-31 18:54
작성일 23-03-31 18:54

본문

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

  • 회사 :
  • 대표 :
  • 주소 :
  • 메일 : admin@mysample.com
  • 사업자 등록번호 :
Copyright © cginjs.com All rights reserved.
notice