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

자료실

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

페이지 정보

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

본문

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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