Internationalization IntlCalendar::fieldDifference

IntlCalendar::fieldDifference

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::fieldDifference — 주어진 시간과 이 객체의 시간의 차이 계산


설명

객체 지향 스타일

public IntlCalendar::fieldDifference(float $timestamp, int $field): int|false

절차적 스타일

intlcal_field_difference(IntlCalendar $calendar, float $timestamp, int $field): int|false

field 매개변수에 지정된 수량과 관련하여 주어진 시간과 이 객체가 설정된 시간 사이의 차이를 반환합니다.

이 메서드는 가장 중요한 관심 필드부터 가장 중요하지 않은 필드까지 차례로 호출해야 합니다. 이를 위해 부작용으로 지정된 필드에 대한 이 달력의 값이 반환된 금액만큼 증가합니다.


매개변수

calendar
IntlCalendar 인스턴스입니다.
timestamp
field가 나타내는 수량을 비교할 시간입니다. 결과가 양수이려면 이 매개변수에 지정된 시간이 메서드가 호출되는 개체의 시간보다 빨라야 합니다.
field
비교할 수량을 나타내는 필드입니다.

IntlCalendar 날짜/시간 필드 상수 중 하나입니다. 0IntlCalendar::FIELD_COUNT 사이의 정수 값입니다.


반환 값

지정된 필드와 연결된 단위의 (부호 있는) 시간 차이를 반환하거나 실패 시 false를 반환합니다.


Examples

예제 #1 IntlCalendar::fieldDifference()

                  
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'fr_FR');

$cal1 = IntlCalendar::fromDateTime('2012-02-29 09:00:11');
$cal2 = IntlCalendar::fromDateTime('2013-03-01 09:19:29');
$time = $cal2->getTime();

echo "Time before: ", IntlDateFormatter::formatObject($cal1), "\n";

printf(
    "The difference in time is %d year(s), %d month(s), "
  . "%d day(s), %d hour(s) and %d minute(s)\n",
    $cal1->fieldDifference($time, IntlCalendar::FIELD_YEAR),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_MONTH),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_DAY_OF_MONTH),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_HOUR_OF_DAY),
    $cal1->fieldDifference($time, IntlCalendar::FIELD_MINUTE)
);

//now it was advanced to the target time, exception for the seconds,
//for which we did not measure the difference
echo "Time after: ", IntlDateFormatter::formatObject($cal1), "\n";
                  
                

위의 예는 다음을 출력합니다.

Time before: 29 févr. 2012 09:00:11
The difference in time is 1 year(s), 0 month(s), 1 day(s), 0 hour(s) and 19 minute(s)
Time after: 1 mars 2013 09:19:11