Skip to content

Latest commit

 

History

History
437 lines (317 loc) · 9 KB

Time.ru.md

File metadata and controls

437 lines (317 loc) · 9 KB

Time

  • класс 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 the sec, min, hour and other keys::
  • Time ::seconds() - Returns the current time in seconds (like the millis() method only in seconds)
  • Time ::millis() - Returns the current time in milliseconds. Note that
  • Time ::nanos() - Returns the current value of the running Java Virtual Machine's

Методы


Статичные Методы

now()

Time::now(php\time\TimeZone $timeZone, php\util\Locale $locale): Time

Returns now time object (date + time)


today()

Time::today(php\time\TimeZone $timeZone, php\util\Locale $locale): Time

Returns today date (without time)


of()

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


seconds()

Time::seconds(): int

Returns the current time in seconds (like the millis() method only in seconds)


millis()

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.


nanos()

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()

__construct(int $date, php\time\TimeZone $timezone, php\util\Locale $locale): void

Create a new time with unix timestamp


getTime()

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()

getTimeZone(): TimeZone

Get timezone of the time object


year()

year(): int

Get the current year

Examples:

  • Вывести текущий код
$now = Time::now();
echo $now->year();

month()

month(): int

Get the current month of the year, 1 - Jan, 12 - Dec


week()

week(): int

Get week of year


weekOfMonth()

weekOfMonth(): int

Get week of month


day()

day(): int

Get day of year


dayOfMonth()

dayOfMonth(): int

Get day of month


dayOfWeek()

dayOfWeek(): int

Get day of week


dayOfWeekInMonth()

dayOfWeekInMonth(): int

hour()

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()

hourOfDay(): int

Get hour of the day


minute()

minute(): int

Get minute of the hour


second()

second(): int

Get second of the minute


millisecond()

millisecond(): int

Get millisecond of the second


compare()

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()

withTimeZone(php\time\TimeZone $timeZone): Time

withLocale()

withLocale(php\util\Locale $locale): Time

add()

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()

replace(array $args): Time

Clones the current datetime and replaces some fields to new values $args


toString()

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()

__toString(): string

Format the time to yyyy-MM-dd'T'HH:mm:ss


__clone()

__clone(): void

Class is immutable, the disallowed clone method