IntlCalendar::fieldDifference
(PHP 5.5.0, PECL >= 3.0.0a1)
IntlCalendar::fieldDifference — Calculate difference between given time and this objectʼs time
Описание
Объектно-ориентированный стиль
$when
, int $field
)Процедурный стиль
Return the difference between the given time and the time this object is
set to, with respect to the quantity specified the
field
parameter.
This method is meant to be called successively, first with the most significant field of interest down to the least significant field. To this end, as a side effect, this calendarʼs value for the field specified is advanced by the amount returned.
Список параметров
-
cal
-
The IntlCalendar resource.
-
when
-
The time against which to compare the quantity represented by the
field
. For the result to be positive, the time given for this parameter must be ahead of the time of the object the method is being invoked on. -
field
-
The field that represents the quantity being compared.
One of the IntlCalendar date/time field constants. These are integer values between 0 and
IntlCalendar::FIELD_COUNT
.
Возвращаемые значения
Returns a (signed) difference of time in the unit associated with the
specified field или FALSE
в случае возникновения ошибки.
Примеры
Пример #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
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Internationalization Functions
- Функция IntlCalendar::add() - Add a (signed) amount of time to a field
- Функция IntlCalendar::after() - Whether this objectʼs time is after that of the passed object
- Функция IntlCalendar::before() - Whether this objectʼs time is before that of the passed object
- Функция IntlCalendar::clear() - Clear a field or all fields
- Функция IntlCalendar::__construct() - Private constructor for disallowing instantiation
- Функция IntlCalendar::createInstance() - Create a new IntlCalendar
- Функция IntlCalendar::equals() - Compare time of two IntlCalendar objects for equality
- Функция IntlCalendar::fieldDifference() - Calculate difference between given time and this objectʼs time
- Функция IntlCalendar::fromDateTime() - Create an IntlCalendar from a DateTime object or string
- Функция IntlCalendar::get() - Get the value for a field
- Функция IntlCalendar::getActualMaximum() - The maximum value for a field, considering the objectʼs current time
- Функция IntlCalendar::getActualMinimum() - The minimum value for a field, considering the objectʼs current time
- Функция IntlCalendar::getAvailableLocales() - Get array of locales for which there is data
- Функция IntlCalendar::getDayOfWeekType() - Tell whether a day is a weekday, weekend or a day that has a transition between the two
- Функция IntlCalendar::getErrorCode() - Get last error code on the object
- Функция IntlCalendar::getErrorMessage() - Get last error message on the object
- Функция IntlCalendar::getFirstDayOfWeek() - Get the first day of the week for the calendarʼs locale
- Функция IntlCalendar::getGreatestMinimum() - Get the largest local minimum value for a field
- Функция IntlCalendar::getKeywordValuesForLocale() - Get set of locale keyword values
- Функция IntlCalendar::getLeastMaximum() - Get the smallest local maximum for a field
- Функция IntlCalendar::getLocale() - Get the locale associated with the object
- Функция IntlCalendar::getMaximum() - Get the global maximum value for a field
- Функция IntlCalendar::getMinimalDaysInFirstWeek() - Get minimal number of days the first week in a year or month can have
- Функция IntlCalendar::getMinimum() - Get the global minimum value for a field
- Функция IntlCalendar::getNow() - Get number representing the current time
- Функция IntlCalendar::getRepeatedWallTimeOption() - Get behavior for handling repeating wall time
- Функция IntlCalendar::getSkippedWallTimeOption() - Get behavior for handling skipped wall time
- Функция IntlCalendar::getTime() - Get time currently represented by the object
- Функция IntlCalendar::getTimeZone() - Get the objectʼs timezone
- Функция IntlCalendar::getType() - Get the calendar type
- Функция IntlCalendar::getWeekendTransition() - Get time of the day at which weekend begins or ends
- Функция IntlCalendar::inDaylightTime() - Whether the objectʼs time is in Daylight Savings Time
- Функция IntlCalendar::isEquivalentTo() - Whether another calendar is equal but for a different time
- Функция IntlCalendar::isLenient() - Whether date/time interpretation is in lenient mode
- Функция IntlCalendar::isSet() - Whether a field is set
- Функция IntlCalendar::isWeekend() - Whether a certain date/time is in the weekend
- Функция IntlCalendar::roll() - Add value to field without carrying into more significant fields
- Функция IntlCalendar::set() - Set a time field or several common fields at once
- Функция IntlCalendar::setFirstDayOfWeek() - Set the day on which the week is deemed to start
- Функция IntlCalendar::setLenient() - Set whether date/time interpretation is to be lenient
- Функция IntlCalendar::setMinimalDaysInFirstWeek() - Set minimal number of days the first week in a year or month can have
- Функция IntlCalendar::setRepeatedWallTimeOption() - Set behavior for handling repeating wall times at negative timezone offset transitions
- Функция IntlCalendar::setSkippedWallTimeOption() - Set behavior for handling skipped wall times at positive timezone offset transitions
- Функция IntlCalendar::setTime() - Set the calendar time in milliseconds since the epoch
- Функция IntlCalendar::setTimeZone() - Set the timezone used by this calendar
- Функция IntlCalendar::toDateTime() - Convert an IntlCalendar into a DateTime object
Коментарии
404 Not Found