Time¶
-
php\time\Time
Class Time, Immutable
Methods
__construct
($date, $timezone = null)¶
Parameters:
- $date – int - unix long timestamp (in millis)
- $timezone – php\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.
Returns: int
getTimeZone
()¶Get timezone of the time object
Returns: php\time\TimeZone
year
()¶Get the current year
Returns: int
month
()¶Get the current month of the year, 1 - Jan, 12 - Dec
Returns: int
week
()¶Get week of year
Returns: int
weekOfMonth
()¶Get week of month
Returns: int
day
()¶Get day of year
Returns: int
dayOfMonth
()¶Get day of month
Returns: int
dayOfWeek
()¶Get day of week
Returns: int
dayOfWeekInMonth
()¶
Returns: 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.
Returns: int
hourOfDay
()¶Get hour of the day
Returns: int
minute
()¶Get minute of the hour
Returns: int
second
()¶Get second of the minute
Returns: int
millisecond
()¶Get millisecond of the second
Returns: 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 thisTime
; a value less than0
if the time of thisTime
is before the time represented by the argument; and a value greater than0
if the time of thisTime
is after the time represented by the argument.
Parameters:
- $time – php\time\Time
Returns: int
withTimeZone
($timeZone)¶
Parameters:
- $timeZone – php\time\TimeZone
Returns:
add
($args)¶Get a new time + $args
use negative values to minus
Parameters:
- $args – array - [millis, sec, min, hour, day, month, year]
Returns:
replace
($args)¶Clones the current datetime and replaces some fields to new values $args
Parameters:
- $args – array - [millis, sec, min, hour, day, month, year]
Returns:
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
Parameters:
- $format – string - date time format
Returns: string
__toString
()¶Format the time to yyyy-MM-dd’T’HH:mm:ss
Returns: string
__clone
()¶private
- static
now
($timeZone = null)¶Returns now time object (date + time)
Parameters:
- $timeZone – php\time\TimeZone
Returns:
- static
today
($timeZone = null)¶Returns today date (without time)
Parameters:
- $timeZone – php\time\TimeZone
Returns:
- 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
Parameters:
- $args – array - [millis, sec, min, hour, day, month, year]
- $timeZone – php\time\TimeZone - if null then it uses the default timezone
Returns:
- static
seconds
¶Returns the current time in seconds (like the
millis()
method only in seconds)
Returns: 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.
Returns: 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
Returns: int