Time

php\time\Time

Class Time, Immutable

Methods


__construct($date, $timezone = null)
Параметры:
  • $dateint - unix long timestamp (in millis)
  • $timezonephp\time\TimeZone - - if null then gets default timezone
getTime()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Time object.

Результат:int
getTimeZone()

Get timezone of the time object

Результат:php\time\TimeZone
year()

Get the current year

Результат:int
month()

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

Результат:int
week()

Get week of year

Результат:int
weekOfMonth()

Get week of month

Результат:int
day()

Get day of year

Результат:int
dayOfMonth()

Get day of month

Результат:int
dayOfWeek()

Get day of week

Результат:int
dayOfWeekInMonth()
Результат:int
hour()

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.

Результат:int
hourOfDay()

Get hour of the day

Результат:int
minute()

Get minute of the hour

Результат:int
second()

Get second of the minute

Результат:int
millisecond()

Get millisecond of the second

Результат:int
compare($time)

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.

Параметры:
Результат:

int

withTimeZone($timeZone)
Параметры:
Результат:

php\time\Time

add($args)

Get a new time + $args

use negative values to minus

Параметры:
  • $argsarray - [millis, sec, min, hour, day, month, year]
Результат:

php\time\Time

replace($args)

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

Параметры:
  • $argsarray - [millis, sec, min, hour, day, month, year]
Результат:

php\time\Time

toString($format)

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
Параметры:
  • $formatstring - date time format
Результат:

string

__toString()

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

Результат:string
__clone()

private

static now($timeZone = null)

Returns now time object (date + time)

Параметры:
Результат:

php\time\Time

static today($timeZone = null)

Returns today date (without time)

Параметры:
Результат:

php\time\Time

static of($args, $timeZone = null)

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
Параметры:
  • $argsarray - [millis, sec, min, hour, day, month, year]
  • $timeZonephp\time\TimeZone - if null then it uses the default timezone
Результат:

php\time\Time

static seconds

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

Результат:int
static millis

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.

Результат:int
static nanos

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

Результат:int