복붙노트

PHP 날짜 시간 이후로 경과 된 시간을 찾는 방법은 무엇입니까? [복제]

PHP

PHP 날짜 시간 이후로 경과 된 시간을 찾는 방법은 무엇입니까? [복제]

2010-04-28 17:25:43과 같은 날짜 타임 스탬프 이후로 경과 된 시간을 찾는 방법 최종 텍스트는 xx Minutes Ago / xx Days Ago와 같아야합니다.

해결법

  1. ==============================

    1.대부분의 해답은 날짜를 문자열로 변환하는 데 중점을 둔 것으로 보입니다. 그것은 '5 일 전'형식으로 날짜를 가져 오는 것에 대해 대부분 생각하고있는 것 같습니다. 맞습니까?

    대부분의 해답은 날짜를 문자열로 변환하는 데 중점을 둔 것으로 보입니다. 그것은 '5 일 전'형식으로 날짜를 가져 오는 것에 대해 대부분 생각하고있는 것 같습니다. 맞습니까?

    이것은 내가 그 일을하는 방법입니다.

    $time = strtotime('2010-04-28 17:25:43');
    
    echo 'event happened '.humanTiming($time).' ago';
    
    function humanTiming ($time)
    {
    
        $time = time() - $time; // to get the time since that moment
        $time = ($time<1)? 1 : $time;
        $tokens = array (
            31536000 => 'year',
            2592000 => 'month',
            604800 => 'week',
            86400 => 'day',
            3600 => 'hour',
            60 => 'minute',
            1 => 'second'
        );
    
        foreach ($tokens as $unit => $text) {
            if ($time < $unit) continue;
            $numberOfUnits = floor($time / $unit);
            return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
        }
    
    }
    

    나는 그것을 테스트하지는 않았지만 효과가있다.

    결과는 다음과 같을 것이다.

    event happened 4 days ago
    

    또는

    event happened 1 minute ago
    

    건배

  2. ==============================

    2.사람이 읽을 수있는 시간 형식과 같은 문법적으로 올바른 페이스 북의 PHP 함수를 공유하고 싶습니다.

    사람이 읽을 수있는 시간 형식과 같은 문법적으로 올바른 페이스 북의 PHP 함수를 공유하고 싶습니다.

    예:

    echo get_time_ago(strtotime('now'));
    

    결과:

    미만 1 분 전

    function get_time_ago($time_stamp)
    {
        $time_difference = strtotime('now') - $time_stamp;
    
        if ($time_difference >= 60 * 60 * 24 * 365.242199)
        {
            /*
             * 60 seconds/minute * 60 minutes/hour * 24 hours/day * 365.242199 days/year
             * This means that the time difference is 1 year or more
             */
            return get_time_ago_string($time_stamp, 60 * 60 * 24 * 365.242199, 'year');
        }
        elseif ($time_difference >= 60 * 60 * 24 * 30.4368499)
        {
            /*
             * 60 seconds/minute * 60 minutes/hour * 24 hours/day * 30.4368499 days/month
             * This means that the time difference is 1 month or more
             */
            return get_time_ago_string($time_stamp, 60 * 60 * 24 * 30.4368499, 'month');
        }
        elseif ($time_difference >= 60 * 60 * 24 * 7)
        {
            /*
             * 60 seconds/minute * 60 minutes/hour * 24 hours/day * 7 days/week
             * This means that the time difference is 1 week or more
             */
            return get_time_ago_string($time_stamp, 60 * 60 * 24 * 7, 'week');
        }
        elseif ($time_difference >= 60 * 60 * 24)
        {
            /*
             * 60 seconds/minute * 60 minutes/hour * 24 hours/day
             * This means that the time difference is 1 day or more
             */
            return get_time_ago_string($time_stamp, 60 * 60 * 24, 'day');
        }
        elseif ($time_difference >= 60 * 60)
        {
            /*
             * 60 seconds/minute * 60 minutes/hour
             * This means that the time difference is 1 hour or more
             */
            return get_time_ago_string($time_stamp, 60 * 60, 'hour');
        }
        else
        {
            /*
             * 60 seconds/minute
             * This means that the time difference is a matter of minutes
             */
            return get_time_ago_string($time_stamp, 60, 'minute');
        }
    }
    
    function get_time_ago_string($time_stamp, $divisor, $time_unit)
    {
        $time_difference = strtotime("now") - $time_stamp;
        $time_units      = floor($time_difference / $divisor);
    
        settype($time_units, 'string');
    
        if ($time_units === '0')
        {
            return 'less than 1 ' . $time_unit . ' ago';
        }
        elseif ($time_units === '1')
        {
            return '1 ' . $time_unit . ' ago';
        }
        else
        {
            /*
             * More than "1" $time_unit. This is the "plural" message.
             */
            // TODO: This pluralizes the time unit, which is done by adding "s" at the end; this will not work for i18n!
            return $time_units . ' ' . $time_unit . 's ago';
        }
    }
    
  3. ==============================

    3.나는 내가 원하는 것을해야하는 기능을 가지고 있다고 생각한다.

    나는 내가 원하는 것을해야하는 기능을 가지고 있다고 생각한다.

    function time2string($timeline) {
        $periods = array('day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1);
    
        foreach($periods AS $name => $seconds){
            $num = floor($timeline / $seconds);
            $timeline -= ($num * $seconds);
            $ret .= $num.' '.$name.(($num > 1) ? 's' : '').' ';
        }
    
        return trim($ret);
    }
    

    단순히 time ()과 strtotime ( '2010-04-28 17:25:43')의 차이에 다음과 같이 적용하면됩니다.

    print time2string(time()-strtotime('2010-04-28 17:25:43')).' ago';
    
  4. ==============================

    4.php Datetime 클래스를 사용한다면 다음을 사용할 수 있습니다 :

    php Datetime 클래스를 사용한다면 다음을 사용할 수 있습니다 :

    function time_ago(Datetime $date) {
      $time_ago = '';
    
      $diff = $date->diff(new Datetime('now'));
    
    
      if (($t = $diff->format("%m")) > 0)
        $time_ago = $t . ' months';
      else if (($t = $diff->format("%d")) > 0)
        $time_ago = $t . ' days';
      else if (($t = $diff->format("%H")) > 0)
        $time_ago = $t . ' hours';
      else
        $time_ago = 'minutes';
    
      return $time_ago . ' ago (' . $date->format('M j, Y') . ')';
    }
    
  5. ==============================

    5.수학적으로 계산 된 예제의 대부분은 2038-01-18 날짜의 하드 한도가 있으며 허구의 날짜에는 사용할 수 없다는 경고를받습니다.

    수학적으로 계산 된 예제의 대부분은 2038-01-18 날짜의 하드 한도가 있으며 허구의 날짜에는 사용할 수 없다는 경고를받습니다.

    DateTime 및 DateInterval 기반 예제가 없기 때문에 OP의 필요성을 충족시키는 다목적 함수와 2 일 전과 같은 복합 경과 기간을 원하는 다목적 함수를 제공하고자했습니다. 경과 시간 대신 날짜를 표시하는 제한이나 경과 시간 결과의 일부를 필터링하는 것과 같은 다른 유스 케이스와 함께.

    또한 예제의 대부분은 경과 시간이 현재 시간에서라고 가정합니다. 아래 함수는 원하는 종료 날짜로 재정의 할 수 있습니다.

    /**
     * multi-purpose function to calculate the time elapsed between $start and optional $end
     * @param string|null $start the date string to start calculation
     * @param string|null $end the date string to end calculation
     * @param string $suffix the suffix string to include in the calculated string
     * @param string $format the format of the resulting date if limit is reached or no periods were found
     * @param string $separator the separator between periods to use when filter is not true
     * @param null|string $limit date string to stop calculations on and display the date if reached - ex: 1 month
     * @param bool|array $filter false to display all periods, true to display first period matching the minimum, or array of periods to display ['year', 'month']
     * @param int $minimum the minimum value needed to include a period
     * @return string
     */
    function elapsedTimeString($start, $end = null, $limit = null, $filter = true, $suffix = 'ago', $format = 'Y-m-d', $separator = ' ', $minimum = 1)
    {
        $dates = (object) array(
            'start' => new DateTime($start ? : 'now'),
            'end' => new DateTime($end ? : 'now'),
            'intervals' => array('y' => 'year', 'm' => 'month', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second'),
            'periods' => array()
        );
        $elapsed = (object) array(
            'interval' => $dates->start->diff($dates->end),
            'unknown' => 'unknown'
        );
        if ($elapsed->interval->invert === 1) {
            return trim('0 seconds ' . $suffix);
        }
        if (false === empty($limit)) {
            $dates->limit = new DateTime($limit);
            if (date_create()->add($elapsed->interval) > $dates->limit) {
                return $dates->start->format($format) ? : $elapsed->unknown;
            }
        }
        if (true === is_array($filter)) {
            $dates->intervals = array_intersect($dates->intervals, $filter);
            $filter = false;
        }
        foreach ($dates->intervals as $period => $name) {
            $value = $elapsed->interval->$period;
            if ($value >= $minimum) {
                $dates->periods[] = vsprintf('%1$s %2$s%3$s', array($value, $name, ($value !== 1 ? 's' : '')));
                if (true === $filter) {
                    break;
                }
            }
        }
        if (false === empty($dates->periods)) {
            return trim(vsprintf('%1$s %2$s', array(implode($separator, $dates->periods), $suffix)));
        }
    
        return $dates->start->format($format) ? : $elapsed->unknown;
    }
    

    한 가지주의해야 할 것은 - 제공된 필터 값에 대해 검색된 간격이 다음 기간으로 이어지지 않는다는 것입니다. 필터는 제공된 마침표의 결과 값을 표시하고 마침표를 다시 계산하여 원하는 필터 합계 만 표시하지 않습니다.

    용법

    OP가 가장 높은 기간을 표시해야하는 경우 (2015-02-24 기준).

    echo elapsedTimeString('2010-04-26');
    /** 4 years ago */
    

    복합 기간을 표시하고 맞춤 종료일을 제공합니다 (제공된 시간 및 허구의 날짜가 없음).

    echo elapsedTimeString('1920-01-01', '2500-02-24', null, false);
    /** 580 years 1 month 23 days ago */
    

    필터링 된 마침표의 결과를 표시하려면 배열의 순서는 중요하지 않습니다.

    echo elapsedTimeString('2010-05-26', '2012-02-24', null, ['month', 'year']);
    /** 1 year 8 months ago */
    

    제한에 도달하면 제공된 형식 (기본값 Y-m-d)으로 시작 날짜를 표시합니다.

    echo elapsedTimeString('2010-05-26', '2012-02-24', '1 year');
    /** 2010-05-26 */
    

    다른 유스 케이스가 많다. 또한 start, end 또는 limit 인수에 대해 유닉스 타임 스탬프 및 / 또는 DateInterval 객체를 받아들이도록 쉽게 조정할 수 있습니다.

  6. ==============================

    6.나는 Mithun의 코드가 마음에 들었지만 좀 더 합리적인 답을주기 위해 약간 수정했다.

    나는 Mithun의 코드가 마음에 들었지만 좀 더 합리적인 답을주기 위해 약간 수정했다.

    function getTimeSince($eventTime)
    {
        $totaldelay = time() - strtotime($eventTime);
        if($totaldelay <= 0)
        {
            return '';
        }
        else
        {
            $first = '';
            $marker = 0;
            if($years=floor($totaldelay/31536000))
            {
                $totaldelay = $totaldelay % 31536000;
                $plural = '';
                if ($years > 1) $plural='s';
                $interval = $years." year".$plural;
                $timesince = $timesince.$first.$interval;
                if ($marker) return $timesince;
                $marker = 1;
                $first = ", ";
            }
            if($months=floor($totaldelay/2628000))
            {
                $totaldelay = $totaldelay % 2628000;
                $plural = '';
                if ($months > 1) $plural='s';
                $interval = $months." month".$plural;
                $timesince = $timesince.$first.$interval;
                if ($marker) return $timesince;
                $marker = 1;
                $first = ", ";
            }
            if($days=floor($totaldelay/86400))
            {
                $totaldelay = $totaldelay % 86400;
                $plural = '';
                if ($days > 1) $plural='s';
                $interval = $days." day".$plural;
                $timesince = $timesince.$first.$interval;
                if ($marker) return $timesince;
                $marker = 1;
                $first = ", ";
            }
            if ($marker) return $timesince;
            if($hours=floor($totaldelay/3600))
            {
                $totaldelay = $totaldelay % 3600;
                $plural = '';
                if ($hours > 1) $plural='s';
                $interval = $hours." hour".$plural;
                $timesince = $timesince.$first.$interval;
                if ($marker) return $timesince;
                $marker = 1;
                $first = ", ";
    
            }
            if($minutes=floor($totaldelay/60))
            {
                $totaldelay = $totaldelay % 60;
                $plural = '';
                if ($minutes > 1) $plural='s';
                $interval = $minutes." minute".$plural;
                $timesince = $timesince.$first.$interval;
                if ($marker) return $timesince;
                $first = ", ";
            }
            if($seconds=floor($totaldelay/1))
            {
                $totaldelay = $totaldelay % 1;
                $plural = '';
                if ($seconds > 1) $plural='s';
                $interval = $seconds." second".$plural;
                $timesince = $timesince.$first.$interval;
            }        
            return $timesince;
    
        }
    }
    
  7. ==============================

    7.@arnorhs 대답을 향상시키기 위해 사용자가 가입 한 후 예를 들어 년, 월, 일 및 시간을 원하면보다 정확한 결과를 얻을 수있는 기능을 추가했습니다.

    @arnorhs 대답을 향상시키기 위해 사용자가 가입 한 후 예를 들어 년, 월, 일 및 시간을 원하면보다 정확한 결과를 얻을 수있는 기능을 추가했습니다.

    반환 할 정밀도 포인트 수를 지정할 수 있도록 새 매개 변수를 추가했습니다.

    function get_friendly_time_ago($distant_timestamp, $max_units = 3) {
        $i = 0;
        $time = time() - $distant_timestamp; // to get the time since that moment
        $tokens = [
            31536000 => 'year',
            2592000 => 'month',
            604800 => 'week',
            86400 => 'day',
            3600 => 'hour',
            60 => 'minute',
            1 => 'second'
        ];
    
        $responses = [];
        while ($i < $max_units && $time > 0) {
            foreach ($tokens as $unit => $text) {
                if ($time < $unit) {
                    continue;
                }
                $i++;
                $numberOfUnits = floor($time / $unit);
    
                $responses[] = $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : '');
                $time -= ($unit * $numberOfUnits);
                break;
            }
        }
    
        if (!empty($responses)) {
            return implode(', ', $responses) . ' ago';
        }
    
        return 'Just now';
    }
    
  8. ==============================

    8.PHP의 모든 버전에서 작동 할 수있는 한 가지 옵션은 이미 제안 된 것을 수행하는 것입니다.

    PHP의 모든 버전에서 작동 할 수있는 한 가지 옵션은 이미 제안 된 것을 수행하는 것입니다.

    $eventTime = '2010-04-28 17:25:43';
    $age = time() - strtotime($eventTime);
    

    그것은 초를 당신에게 줄 것이다. 거기에서 원하는대로 표시 할 수 있습니다.

    그러나이 접근법의 한 가지 문제점은 DST로 인한 시간 이동을 고려하지 않는다는 것입니다. 그것이 문제가되지 않는다면, 그걸로 가십시오. 그렇지 않으면 아마도 DateTime 클래스에서 diff () 메서드를 사용하려고 할 것입니다. 불행히도, PHP 5.3 이상인 경우에만 옵션입니다.

  9. ==============================

    9.이 제품을 사용하면

    이 제품을 사용하면

        $previousDate = '2013-7-26 17:01:10';
        $startdate = new DateTime($previousDate);
        $endDate   = new DateTime('now');
        $interval  = $endDate->diff($startdate);
        echo$interval->format('%y years, %m months, %d days');
    

    이것을 참조하십시오. http://ca2.php.net/manual/en/dateinterval.format.php

  10. ==============================

    10.다음 repos 중 하나를 시도해보십시오.

    다음 repos 중 하나를 시도해보십시오.

    https://github.com/salavert/time-ago-in-words

    https://github.com/jimmiw/php-time-ago

    방금 후자를 사용하기 시작했는데 트릭을하지만, 문제의 날짜가 너무 먼 정확한 날짜에 stackoverflow 스타일의 대체물이 없거나 미래의 날짜에 대한 지원이 없으며 API는 약간 펑키하지만 적어도 겉보기에 완벽하게 작동하고 유지 관리됩니다 ...

  11. ==============================

    11.[saved_date]를 타임 스탬프로 변환하십시오. 현재 타임 스탬프를 가져옵니다.

    [saved_date]를 타임 스탬프로 변환하십시오. 현재 타임 스탬프를 가져옵니다.

    현재 시간 소인 - [saved_date] 시간 소인.

    그런 다음 date ();

    일반적으로 대부분의 날짜 형식을 strtotime () 함수를 사용하여 타임 스탬프로 변환 할 수 있습니다.

  12. ==============================

    12.경과 된 시간을 찾으려면, 보통 date () 대신에 time ()을 사용하고 형식화 된 타임 스탬프를 사용하십시오. 그런 다음 후자 값과 이전 값의 차이를 가져 와서 그에 따라 형식을 지정하십시오. time ()은 date ()를 대신하는 것이 아니라 경과 시간을 계산할 때 완전히 도움이됩니다.

    경과 된 시간을 찾으려면, 보통 date () 대신에 time ()을 사용하고 형식화 된 타임 스탬프를 사용하십시오. 그런 다음 후자 값과 이전 값의 차이를 가져 와서 그에 따라 형식을 지정하십시오. time ()은 date ()를 대신하는 것이 아니라 경과 시간을 계산할 때 완전히 도움이됩니다.

    예:

    time () 값은 1 초마다 1274467343 씩 증가합니다. 따라서 값이 1274467343 인 $ erlierTime과 값이 1274467500 인 $ 후천 시간을 가질 수 있습니다. 그런 다음 $afterTime - $ erlierTime을 수행하여 초 단위로 시간을 얻으십시오.

  13. ==============================

    13.내 자신을 썼다.

    내 자신을 썼다.

    function getElapsedTime($eventTime)
    {
        $totaldelay = time() - strtotime($eventTime);
        if($totaldelay <= 0)
        {
            return '';
        }
        else
        {
            if($days=floor($totaldelay/86400))
            {
                $totaldelay = $totaldelay % 86400;
                return $days.' days ago.';
            }
            if($hours=floor($totaldelay/3600))
            {
                $totaldelay = $totaldelay % 3600;
                return $hours.' hours ago.';
            }
            if($minutes=floor($totaldelay/60))
            {
                $totaldelay = $totaldelay % 60;
                return $minutes.' minutes ago.';
            }
            if($seconds=floor($totaldelay/1))
            {
                $totaldelay = $totaldelay % 1;
                return $seconds.' seconds ago.';
            }
        }
    }
    
  14. ==============================

    14.여기에 날짜 시간 이후 경과 된 시간을 찾기 위해 사용자 지정 함수를 사용하고 있습니다.

    여기에 날짜 시간 이후 경과 된 시간을 찾기 위해 사용자 지정 함수를 사용하고 있습니다.

    
    echo Datetodays('2013-7-26 17:01:10');
    
    function Datetodays($d) {
    
            $date_start = $d;
            $date_end = date('Y-m-d H:i:s');
    
            define('SECOND', 1);
            define('MINUTE', SECOND * 60);
            define('HOUR', MINUTE * 60);
            define('DAY', HOUR * 24);
            define('WEEK', DAY * 7);
    
            $t1 = strtotime($date_start);
            $t2 = strtotime($date_end);
            if ($t1 > $t2) {
                $diffrence = $t1 - $t2;
            } else {
                $diffrence = $t2 - $t1;
            }
    
            //echo "
    ".$date_end." ".$date_start." ".$diffrence; $results['major'] = array(); // whole number representing larger number in date time relationship $results1 = array(); $string = ''; $results['major']['weeks'] = floor($diffrence / WEEK); $results['major']['days'] = floor($diffrence / DAY); $results['major']['hours'] = floor($diffrence / HOUR); $results['major']['minutes'] = floor($diffrence / MINUTE); $results['major']['seconds'] = floor($diffrence / SECOND); //print_r($results); // Logic: // Step 1: Take the major result and transform it into raw seconds (it will be less the number of seconds of the difference) // ex: $result = ($results['major']['weeks']*WEEK) // Step 2: Subtract smaller number (the result) from the difference (total time) // ex: $minor_result = $difference - $result // Step 3: Take the resulting time in seconds and convert it to the minor format // ex: floor($minor_result/DAY) $results1['weeks'] = floor($diffrence / WEEK); $results1['days'] = floor((($diffrence - ($results['major']['weeks'] * WEEK)) / DAY)); $results1['hours'] = floor((($diffrence - ($results['major']['days'] * DAY)) / HOUR)); $results1['minutes'] = floor((($diffrence - ($results['major']['hours'] * HOUR)) / MINUTE)); $results1['seconds'] = floor((($diffrence - ($results['major']['minutes'] * MINUTE)) / SECOND)); //print_r($results1); if ($results1['weeks'] != 0 && $results1['days'] == 0) { if ($results1['weeks'] == 1) { $string = $results1['weeks'] . ' week ago'; } else { if ($results1['weeks'] == 2) { $string = $results1['weeks'] . ' weeks ago'; } else { $string = '2 weeks ago'; } } } elseif ($results1['weeks'] != 0 && $results1['days'] != 0) { if ($results1['weeks'] == 1) { $string = $results1['weeks'] . ' week ago'; } else { if ($results1['weeks'] == 2) { $string = $results1['weeks'] . ' weeks ago'; } else { $string = '2 weeks ago'; } } } elseif ($results1['weeks'] == 0 && $results1['days'] != 0) { if ($results1['days'] == 1) { $string = $results1['days'] . ' day ago'; } else { $string = $results1['days'] . ' days ago'; } } elseif ($results1['days'] != 0 && $results1['hours'] != 0) { $string = $results1['days'] . ' day and ' . $results1['hours'] . ' hours ago'; } elseif ($results1['days'] == 0 && $results1['hours'] != 0) { if ($results1['hours'] == 1) { $string = $results1['hours'] . ' hour ago'; } else { $string = $results1['hours'] . ' hours ago'; } } elseif ($results1['hours'] != 0 && $results1['minutes'] != 0) { $string = $results1['hours'] . ' hour and ' . $results1['minutes'] . ' minutes ago'; } elseif ($results1['hours'] == 0 && $results1['minutes'] != 0) { if ($results1['minutes'] == 1) { $string = $results1['minutes'] . ' minute ago'; } else { $string = $results1['minutes'] . ' minutes ago'; } } elseif ($results1['minutes'] != 0 && $results1['seconds'] != 0) { $string = $results1['minutes'] . ' minute and ' . $results1['seconds'] . ' seconds ago'; } elseif ($results1['minutes'] == 0 && $results1['seconds'] != 0) { if ($results1['seconds'] == 1) { $string = $results1['seconds'] . ' second ago'; } else { $string = $results1['seconds'] . ' seconds ago'; } } return $string; } ?>
  15. ==============================

    15.당신이 직접 양식 WordPress에 대한 기능을 얻을 수있는 파일을 여기에보세요

    당신이 직접 양식 WordPress에 대한 기능을 얻을 수있는 파일을 여기에보세요

    http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/formatting.php#L2121

    function human_time_diff( $from, $to = '' ) {
        if ( empty( $to ) )
            $to = time();
    
        $diff = (int) abs( $to - $from );
    
        if ( $diff < HOUR_IN_SECONDS ) {
            $mins = round( $diff / MINUTE_IN_SECONDS );
            if ( $mins <= 1 )
                $mins = 1;
            /* translators: min=minute */
            $since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
        } elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
            $hours = round( $diff / HOUR_IN_SECONDS );
            if ( $hours <= 1 )
                $hours = 1;
            $since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
        } elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
            $days = round( $diff / DAY_IN_SECONDS );
            if ( $days <= 1 )
                $days = 1;
            $since = sprintf( _n( '%s day', '%s days', $days ), $days );
        } elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
            $weeks = round( $diff / WEEK_IN_SECONDS );
            if ( $weeks <= 1 )
                $weeks = 1;
            $since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
        } elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
            $months = round( $diff / ( 30 * DAY_IN_SECONDS ) );
            if ( $months <= 1 )
                $months = 1;
            $since = sprintf( _n( '%s month', '%s months', $months ), $months );
        } elseif ( $diff >= YEAR_IN_SECONDS ) {
            $years = round( $diff / YEAR_IN_SECONDS );
            if ( $years <= 1 )
                $years = 1;
            $since = sprintf( _n( '%s year', '%s years', $years ), $years );
        }
    
        return $since;
    }
    
  16. ==============================

    16.arnorhs에 의한 "humanTiming"기능의 즉석. 그것은 인간이 읽을 수있는 텍스트 버전으로 시간 문자열의 "완전히 뻗어"번역을 계산합니다. 예를 들어 "1 주일 2 일 1 시간 28 분 14 초"

    arnorhs에 의한 "humanTiming"기능의 즉석. 그것은 인간이 읽을 수있는 텍스트 버전으로 시간 문자열의 "완전히 뻗어"번역을 계산합니다. 예를 들어 "1 주일 2 일 1 시간 28 분 14 초"

    function humantime ($oldtime, $newtime = null, $returnarray = false)    {
        if(!$newtime) $newtime = time();
        $time = $newtime - $oldtime; // to get the time since that moment
        $tokens = array (
                31536000 => 'year',
                2592000 => 'month',
                604800 => 'week',
                86400 => 'day',
                3600 => 'hour',
                60 => 'minute',
                1 => 'second'
        );
        $htarray = array();
        foreach ($tokens as $unit => $text) {
                if ($time < $unit) continue;
                $numberOfUnits = floor($time / $unit);
                $htarray[$text] = $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
                $time = $time - ( $unit * $numberOfUnits );
        }
        if($returnarray) return $htarray;
        return implode(' ', $htarray);
    }
    
  17. ==============================

    17.최근에이 작업을 수행 했어야합니다. 이것이 누군가를 돕기를 바랍니다. 모든 가능성에 부합하지 않지만 프로젝트에 대한 나의 필요를 충족 시켰습니다.

    최근에이 작업을 수행 했어야합니다. 이것이 누군가를 돕기를 바랍니다. 모든 가능성에 부합하지 않지만 프로젝트에 대한 나의 필요를 충족 시켰습니다.

    https://github.com/duncanheron/twitter_date_format

    https://github.com/duncanheron/twitter_date_format/blob/master/twitter_date_format.php

  18. from https://stackoverflow.com/questions/2915864/php-how-to-find-the-time-elapsed-since-a-date-time by cc-by-sa and MIT license