trait TimeTrait

Methods

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

Constructor.

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

Returns a new instance set to the current time.

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

Returns a new instance according to the specified date.

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

Returns a new instance according to the specified UNIX timestamp.

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

Returns a new instance according to the specified DOS timestamp.

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

Returns a new instance according to the specified time string.

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

Sets the time zone.

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

Move forward in time by x seconds.

$this|TimeTrait|false
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 20
__construct(string $time = 'now', string|DateTimeZone|null $timeZone = null)

Constructor.

Parameters

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

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

Returns a new instance set to the current time.

Parameters

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

Return Value

TimeTrait

at line 50
static TimeTrait|false createFromDate(int $year, int|null $month = null, int|null $day = null, string|DateTimeZone|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)
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

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

Returns a new instance according to the specified UNIX timestamp.

Parameters

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

Return Value

TimeTrait|false

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

Returns a new instance according to the specified DOS timestamp.

Parameters

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

Return Value

TimeTrait|false

at line 102
static TimeTrait|false createFromFormat(string $format, string $time, string|DateTimeZone|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
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

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

Sets the time zone.

Parameters

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

Return Value

$this|TimeTrait|false

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

Move forward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|TimeTrait|false

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

Move backward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|TimeTrait|false

at line 164
int getDOSTimestamp()

Returns the DOS timestamp.

Return Value

int

at line 186
bool isLeapYear()

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

Return Value

bool

at line 203
array daysInMonths()

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

Return Value

array

at line 227
int daysInMonth()

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

Return Value

int

at line 238
string formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

Parameters

string $format Date format

Return Value

string