class Time extends DateTime

Extension of the PHP DateTime class.

Constants

MINUTE

Number of seconds in a minute.

HOUR

Number of seconds in an hour.

DAY

Number of seconds in a day.

WEEK

Number of seconds in a week.

MONTH

Average number of seconds in a month.

YEAR

Average number of seconds in a year.

Methods

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

Constructor.

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

Returns a new Time object.

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

Returns new Time object according to the specified date.

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

Returns new Time object according to the specified timestamp.

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

Returns new Time object according to the specified DOS timestamp.

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

Returns new Time object formatted according to the specified format.

setTimezone(string|DateTimeZone $timeZone)

Sets the time zone for the Time object.

forward(int $seconds)

Move forward in time by x seconds.

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 73
__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 89
static Time now(string|DateTimeZone|null $timeZone = null)

Returns a new Time object.

Parameters

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

Return Value

Time

at line 103
static Time createFromDate(int $year, int|null $month = null, int|null $day = null, string|DateTimeZone|null $timeZone = null)

Returns new Time object 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

Time

at line 121
static Time createFromTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns new Time object according to the specified timestamp.

Parameters

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

Return Value

Time

at line 137
static Time createFromDOSTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns new Time object 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

Time

at line 159
static Time createFromFormat(string $format, string $time, string|DateTimeZone|null $timeZone = null)

Returns new Time object formatted according to the specified format.

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

Time

at line 184
Time setTimezone(string|DateTimeZone $timeZone)

Sets the time zone for the Time object.

Parameters

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

Return Value

Time

at line 200
Time forward(int $seconds)

Move forward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

Time

at line 211
Time rewind(int $seconds)

Move backward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

Time

at line 221
int getDOSTimestamp()

Returns the DOS timestamp.

Return Value

int

at line 243
bool isLeapYear()

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

Return Value

bool

at line 260
array daysInMonths()

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

Return Value

array

at line 284
int daysInMonth()

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

Return Value

int

at line 295
string formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

Parameters

string $format Date format

Return Value

string