- class
Time(php\time\Time) - package
std - source
php/time/Time.php
Description
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,hourand 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): TimeReturns now time object (date + time)
Time::today(php\time\TimeZone $timeZone, php\util\Locale $locale): TimeReturns today date (without time)
Time::of(array $args, php\time\TimeZone $timeZone, php\util\Locale $locale): TimeCreate 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(): intReturns the current time in seconds (like the millis() method only in seconds)
Time::millis(): intReturns 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(): intReturns 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): voidCreate a new time with unix timestamp
getTime(): intReturns 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(): TimeZoneGet timezone of the time object
year(): intGet the current year
Examples:
- Get current year
$now = Time::now();
echo $now->year();month(): intGet the current month of the year, 1 - Jan, 12 - Dec
week(): intGet week of year
weekOfMonth(): intGet week of month
day(): intGet day of year
dayOfMonth(): intGet day of month
dayOfWeek(): intGet day of week
dayOfWeekInMonth(): inthour(): intGet 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(): intGet hour of the day
minute(): intGet minute of the hour
second(): intGet second of the minute
millisecond(): intGet millisecond of the second
compare(php\time\Time $time): intCompares 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): TimewithLocale(php\util\Locale $locale): Timeadd(array $args): TimeGet a new time + $args
.. note::
use negative values to minus
Examples:
- Add one year to date
$date = Time::of(['year' => 2018, 'month' => 5, 'day' => 1]);
echo $date->year();
$dayPlusYear = $date->add(['year' => 1]);
echo $dayPlusYear->year();- Decrease date by one day
$date = Time::of(['year' => 2018, 'month' => 5, 'day' => 1]);
$newDate = $date->add(['day' => -1]);
echo $newDate->toString('yyyy/MM/dd'); // 2018.04.30replace(array $args): TimeClones the current datetime and replaces some fields to new values $args
toString(string $format, php\util\Locale $locale): stringFormat 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(): stringFormat the time to yyyy-MM-dd'T'HH:mm:ss
__clone(): voidClass is immutable, the disallowed clone method