DateTime
extends DateTime
in package
Uses
DateTimeTrait
Pop utils date-time helper class
Tags
Table of Contents
Properties
- $dateTimeFormat : string|null
- Date-time format
- $dateTimeFormats : array<string|int, mixed>
- Date-time formats
- $defaultDateFormat : string|null
- Default date format
- $defaultTimeFormat : string|null
- Default time format
Methods
- __toString() : string
- __toString method
- create() : static
- Create a new DateTime object
- detectDateTimeFormat() : string|null
- Detect date-time format
- detectFormat() : string|null
- Detect date-time format
- getAverage() : DateInterval|string
- Method to get average time from array of multiple time values in HH:MM:SS format
- getDefaultDateFormat() : string
- Method to get the default date format
- getDefaultTimeFormat() : string
- Method to get the default time format
- getTotal() : DateInterval|string
- Method to get total time from array of multiple time values in HH:MM:SS format
- getWeekDates() : array<string|int, mixed>
- Method to get dates of a week
- hasDefaultDateFormat() : bool
- Method to see if the object as a default date format
- hasDefaultTimeFormat() : bool
- Method to see if the object as a default time format
- setDefaultDateFormat() : static
- Method to set the default date format
- setDefaultTimeFormat() : static
- Method to set the default time format
Properties
$dateTimeFormat
Date-time format
protected
string|null
$dateTimeFormat
= null
$dateTimeFormats
Date-time formats
protected
array<string|int, mixed>
$dateTimeFormats
= ['/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}$/' => 'Y-m-d H:i:s.v', '/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/' => 'Y-m-d H:i:s', '/^\\d{2}\\/\\d{2}\\/\\d{4} \\d{1,2}:\\d{2}\\s(A|P)M$/' => 'm/d/Y g:i A', '/^\\d{2}\\/\\d{2}\\/\\d{2} \\d{1,2}:\\d{2}\\s(A|P)M$/' => 'm/d/y g:i A', '/^\\d{4}-\\d{2}-\\d{2}$/' => 'Y-m-d', '/^\\d{2}\\/\\d{2}\\/\\d{4}$/' => 'm/d/Y', '/^\\d{2}\\.\\d{2}\\.\\d{4}$/' => 'd.m.Y', '/^\\d{2}\\/\\d{2}\\/\\d{2}$/' => 'm/d/y', '/^\\d{2}\\.\\d{2}\\.\\d{2}$/' => 'd.m.y', '/^\\d{2}:\\d{2}:\\d{2}$/' => 'H:i:s', '/^\\d{1,2}:\\d{2}\\s(A|P)M$/' => 'g:i A']
$defaultDateFormat
Default date format
protected
string|null
$defaultDateFormat
= null
$defaultTimeFormat
Default time format
protected
string|null
$defaultTimeFormat
= null
Methods
__toString()
__toString method
public
__toString() : string
Return values
stringcreate()
Create a new DateTime object
public
static create([string $dateTime = 'now' ][, DateTimeZone|null $timeZone = null ][, string|null $defaultDateFormat = null ][, string|null $defaultTimeFormat = null ]) : static
Parameters
- $dateTime : string = 'now'
- $timeZone : DateTimeZone|null = null
- $defaultDateFormat : string|null = null
- $defaultTimeFormat : string|null = null
Tags
Return values
staticdetectDateTimeFormat()
Detect date-time format
public
static detectDateTimeFormat(string $dateTime) : string|null
Parameters
- $dateTime : string
Return values
string|nulldetectFormat()
Detect date-time format
public
detectFormat(string $dateTime) : string|null
Parameters
- $dateTime : string
Return values
string|nullgetAverage()
Method to get average time from array of multiple time values in HH:MM:SS format
public
static getAverage(array<string|int, mixed> $times[, string|null $format = null ][, bool $secondsOnly = false ]) : DateInterval|string
Standard hh:mm:ss format string is '%H:%I:%S'
Parameters
- $times : array<string|int, mixed>
- $format : string|null = null
- $secondsOnly : bool = false
Tags
Return values
DateInterval|stringgetDefaultDateFormat()
Method to get the default date format
public
getDefaultDateFormat() : string
Return values
stringgetDefaultTimeFormat()
Method to get the default time format
public
getDefaultTimeFormat() : string
Return values
stringgetTotal()
Method to get total time from array of multiple time values in HH:MM:SS format
public
static getTotal(array<string|int, mixed> $times[, string|null $format = null ][, bool $secondsOnly = false ]) : DateInterval|string
Standard hh:mm:ss format string is '%H:%I:%S'
Parameters
- $times : array<string|int, mixed>
- $format : string|null = null
- $secondsOnly : bool = false
Tags
Return values
DateInterval|stringgetWeekDates()
Method to get dates of a week
public
static getWeekDates([int|null $week = null ][, int|null $year = null ][, string|null $format = null ]) : array<string|int, mixed>
Parameters
- $week : int|null = null
- $year : int|null = null
- $format : string|null = null
Return values
array<string|int, mixed>hasDefaultDateFormat()
Method to see if the object as a default date format
public
hasDefaultDateFormat() : bool
Return values
boolhasDefaultTimeFormat()
Method to see if the object as a default time format
public
hasDefaultTimeFormat() : bool
Return values
boolsetDefaultDateFormat()
Method to set the default date format
public
setDefaultDateFormat(string $defaultDateFormat) : static
Parameters
- $defaultDateFormat : string
Return values
staticsetDefaultTimeFormat()
Method to set the default time format
public
setDefaultTimeFormat(string $defaultTimeFormat) : static
Parameters
- $defaultTimeFormat : string