trait TimeTrait

Time trait.

Methods

__construct(string $time = 'now', DateTimeZone|string|null $timeZone = null)

Constructor.

static TimeTrait
now(DateTimeZone|string|null $timeZone = null)

Returns a new instance set to the current time.

static false|TimeTrait
createFromDate(int $year, int|null $month = null, int|null $day = null, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified date.

static false|TimeTrait
createFromTimestamp(int $timestamp, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified UNIX timestamp.

static false|TimeTrait
createFromDOSTimestamp(int $timestamp, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified DOS timestamp.

static false|TimeTrait
createFromFormat(string $format, string $time, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified time string.

$this|false|TimeTrait
setTimezone(DateTimeZone|string $timeZone)

Sets the time zone.

$this|false|TimeTrait
forward(int $seconds)

Move forward in time by x seconds.

$this|false|TimeTrait
rewind(int $seconds)

Move backward in time by x seconds.

int
getDOSTimestamp()

Returns the DOS timestamp.

bool
isLeapYear()

Returns TRUE if the year is a leap year and FALSE if not.

array
daysInMonths()

Returns an array containing the number of days in each month of the year.

int
daysInMonth()

Returns the number of days in the current or specified month.

string
formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

Details

at line 28
__construct(string $time = 'now', DateTimeZone|string|null $timeZone = null)

Constructor.

Parameters

string $time A date/time string
DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

at line 44
static TimeTrait now(DateTimeZone|string|null $timeZone = null)

Returns a new instance set to the current time.

Parameters

DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait

at line 58
static false|TimeTrait createFromDate(int $year, int|null $month = null, int|null $day = null, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified date.

Parameters

int $year Year
int|null $month Month (1 to 12)
int|null $day Day of month (1 to 31)
DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

Return Value

false|TimeTrait

at line 76
static false|TimeTrait createFromTimestamp(int $timestamp, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified UNIX timestamp.

Parameters

int $timestamp UNIX timestamp
DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

Return Value

false|TimeTrait

at line 88
static false|TimeTrait createFromDOSTimestamp(int $timestamp, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified DOS timestamp.

Parameters

int $timestamp DOS timestamp
DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

Return Value

false|TimeTrait

at line 110
static false|TimeTrait createFromFormat(string $format, string $time, DateTimeZone|string|null $timeZone = null)

Returns a new instance according to the specified time string.

Parameters

string $format The format that the passed in string should be in
string $time String representing the time
DateTimeZone|string|null $timeZone A valid time zone or a DateTimeZone object

Return Value

false|TimeTrait

at line 135
$this|false|TimeTrait setTimezone(DateTimeZone|string $timeZone)

Sets the time zone.

Parameters

DateTimeZone|string $timeZone A valid time zone or a DateTimeZone object

Return Value

$this|false|TimeTrait

at line 151
$this|false|TimeTrait forward(int $seconds)

Move forward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|false|TimeTrait

at line 162
$this|false|TimeTrait rewind(int $seconds)

Move backward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|false|TimeTrait

at line 172
int getDOSTimestamp()

Returns the DOS timestamp.

Return Value

int

at line 194
bool isLeapYear()

Returns TRUE if the year is a leap year and FALSE if not.

Return Value

bool

at line 211
array daysInMonths()

Returns an array containing the number of days in each month of the year.

Return Value

array

at line 235
int daysInMonth()

Returns the number of days in the current or specified month.

Return Value

int

at line 246
string formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

Parameters

string $format Date format

Return Value

string