- класс
Time
(php\time\Time
) - пакет
std
- исходники
php/time/Time.php
Описание
Class Time, Immutable
Time ::
now()
- Returns now time object (date + time)Time ::
today()
- Returns today date (without time)Time ::
of()
- Create a new time by using the $args arrays that can contain thesec
,min
,hour
and other keys::Time ::
seconds()
- Returns the current time in seconds (like themillis()
method only in seconds)Time ::
millis()
- Returns the current time in milliseconds. Note thatTime ::
nanos()
- Returns the current value of the running Java Virtual Machine's
->
__construct()
- Create a new time with unix timestamp->
getTime()
- Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT->
getTimeZone()
- Get timezone of the time object->
year()
- Get the current year->
month()
- Get the current month of the year, 1 - Jan, 12 - Dec->
week()
- Get week of year->
weekOfMonth()
- Get week of month->
day()
- Get day of year->
dayOfMonth()
- Get day of month->
dayOfWeek()
- Get day of week->
dayOfWeekInMonth()
->
hour()
- Get hour, indicating the hour of the morning or afternoon.->
hourOfDay()
- Get hour of the day->
minute()
- Get minute of the hour->
second()
- Get second of the minute->
millisecond()
- Get millisecond of the second->
compare()
- Compares the time values->
withTimeZone()
->
withLocale()
->
add()
- Get a new time + $args->
replace()
- Clones the current datetime and replaces some fields to new values $args->
toString()
- Format the current datetime to string with $format->
__toString()
- Format the time to yyyy-MM-dd'T'HH:mm:ss->
__clone()
- Class is immutable, the disallowed clone method
Time::now(php\time\TimeZone $timeZone, php\util\Locale $locale): Time
Returns now time object (date + time)
Time::today(php\time\TimeZone $timeZone, php\util\Locale $locale): Time
Returns today date (without time)
Time::of(array $args, php\time\TimeZone $timeZone, php\util\Locale $locale): Time
Create a new time by using the $args arrays that can contain the sec
, min
, hour
and other keys::
$time = Time::of(['year' => 2013, 'month' => 1, 'day' => 1]) // 01 Jan 2013
Time::seconds(): int
Returns the current time in seconds (like the millis()
method only in seconds)
Time::millis(): int
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
Time::nanos(): int
Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.
This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin
__construct(int $date, php\time\TimeZone $timezone, php\util\Locale $locale): void
Create a new time with unix timestamp
getTime(): int
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Time object.
Examples:
- Unix Timestamp
echo Time::now()->getTime() / 1000;
getTimeZone(): TimeZone
Get timezone of the time object
year(): int
Get the current year
Examples:
- Вывести текущий код
$now = Time::now();
echo $now->year();
month(): int
Get the current month of the year, 1 - Jan, 12 - Dec
week(): int
Get week of year
weekOfMonth(): int
Get week of month
day(): int
Get day of year
dayOfMonth(): int
Get day of month
dayOfWeek(): int
Get day of week
dayOfWeekInMonth(): int
hour(): int
Get hour, indicating the hour of the morning or afternoon. hour() is used for the 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12.
hourOfDay(): int
Get hour of the day
minute(): int
Get minute of the hour
second(): int
Get second of the minute
millisecond(): int
Get millisecond of the second
compare(php\time\Time $time): int
Compares the time values
Returns the value 0
if the time represented by the argument
is equal to the time represented by this Time
; a value
less than 0
if the time of this Time
is
before the time represented by the argument; and a value greater than
0
if the time of this Time
is after the
time represented by the argument.
withTimeZone(php\time\TimeZone $timeZone): Time
withLocale(php\util\Locale $locale): Time
add(array $args): Time
Get a new time + $args
.. note::
use negative values to minus
Examples:
- Добавить один год дате
$date = Time::of(['year' => 2018, 'month' => 5, 'day' => 1]);
echo $date->year();
$dayPlusYear = $date->add(['year' => 1]);
echo $dayPlusYear->year();
- Уменьшить дату на один день
$date = Time::of(['year' => 2018, 'month' => 5, 'day' => 1]);
$newDate = $date->add(['day' => -1]);
echo $newDate->toString('yyyy/MM/dd'); // 2018.04.30
replace(array $args): Time
Clones the current datetime and replaces some fields to new values $args
toString(string $format, php\util\Locale $locale): string
Format the current datetime to string with $format
- G Era designator Text AD
- y Year Year 1996; 96
- M Month in year Month July; Jul; 07
- w Week in year Number 27
- W Week in month Number 2
- D Day in year Number 189
- d Day in month Number 10
- F Day of week in month Number 2
- E Day in week Text Tuesday; Tue
- a Am/pm marker Text PM
- H Hour in day (0-23) Number 0
- k Hour in day (1-24) Number 24
- K Hour in am/pm (0-11) Number 0
- h Hour in am/pm (1-12) Number 12
- m Minute in hour Number 30
- s Second in minute Number 55
- S Millisecond Number 978
- z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
- Z Time zone RFC 822 time zone -0800
__toString(): string
Format the time to yyyy-MM-dd'T'HH:mm:ss
__clone(): void
Class is immutable, the disallowed clone method