DateTime extends DateTime
Table of Contents
Methods
- __clone() : void
- Produces the copy of the object.
- __construct() : mixed
- __toString() : string
- Converts a date to the string with default culture format setting.
- add() : $this
- Performs dates arithmetic.
- clone() : static
- convertFormatToPhp() : string
- Converts date format from culture to php format.
- createFromFormat() : self
- createFromMainDateTime() : static
- createFromMainDateTimeOrNull() : static|null
- createFromPhp() : static
- Creates DateTime object from PHP \DateTime object.
- createFromText() : DateTime|null
- Creates Date object from Text (return array of result object) Examples: "end of next week", "tomorrow morning", "friday 25.10"
- createFromTimestamp() : static
- Creates DateTime object from Unix timestamp.
- createFromUserTime() : DateTime
- Creates DateTime object from local user time using global timezone settings and default culture.
- disableUserTime() : $this
- enableUserTime() : $this
- format() : string
- Formats date value to string.
- getDayOfWeek() : int
- getDiff() : DateInterval
- Returns difference between dates.
- getFormat() : string
- Returns a date format from the culture in the php format.
- getTimestamp() : int
- Returns Unix timestamp from date.
- getTimeZone() : DateTimeZone
- Returns timezone object.
- isCorrect() : bool
- Checks the string for correct date (by trying to create Date object).
- isUserTimeEnabled() : bool
- secondsToOffset() : mixed
- setDate() : $this
- Sets the current date of the DateTime object to a different date.
- setDefaultTimeZone() : DateTime
- Sets default timezone.
- setTime() : DateTime
- setTimeZone() : DateTime
- Sets timezone object.
- toPhp() : DateTime
- toString() : string
- Converts date to string, using Culture and global timezone settings.
- toUserTime() : DateTime
- Changes time from server time to user time using global timezone settings.
- tryParse() : DateTime|null
- Creates DateTime object from string.
- withAdd() : static
- withAddSeconds() : static
- withDate() : static
- withTime() : static
- withTimeZone() : static
Methods
__clone()
Produces the copy of the object.
public
__clone() : void
__construct()
public
__construct([string|null $time = null ][, string|null $format = null ][, DateTimeZone|null $timezone = null ]) : mixed
Parameters
- $time : string|null = null
-
String representation of datetime.
- $format : string|null = null
-
PHP datetime format. If not specified, the format is got from the current culture.
- $timezone : DateTimeZone|null = null
-
Optional timezone object.
Tags
__toString()
Converts a date to the string with default culture format setting.
public
__toString() : string
Return values
stringadd()
Performs dates arithmetic.
public
add(string $interval) : $this
Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T. Period Designators: Y - years, M - months, D - days, W - weeks, H - hours, M - minutes, S - seconds. Examples: two days - 2D, two seconds - T2S, six years and five minutes - 6YT5M. The unit types must be entered from the largest scale unit on the left to the smallest scale unit on the right. Use first "-" char for negative periods. OR Relative period. Examples: "+5 weeks", "12 day", "-7 weekdays", '3 months - 5 days'
Parameters
- $interval : string
-
Time interval to add.
Return values
$thisclone()
public
clone() : static
Return values
staticconvertFormatToPhp()
Converts date format from culture to php format.
public
static convertFormatToPhp(string $format) : string
Parameters
- $format : string
-
Format string.
Return values
stringcreateFromFormat()
public
static createFromFormat(string $format, string $dateTime) : self
Parameters
- $format : string
- $dateTime : string
Return values
selfcreateFromMainDateTime()
public
static createFromMainDateTime(DateTime $dateTime) : static
Parameters
- $dateTime : DateTime
Return values
staticcreateFromMainDateTimeOrNull()
public
static createFromMainDateTimeOrNull(DateTime|null $dateTime) : static|null
Parameters
- $dateTime : DateTime|null
Return values
static|nullcreateFromPhp()
Creates DateTime object from PHP \DateTime object.
public
static createFromPhp(DateTime $datetime) : static
Parameters
- $datetime : DateTime
-
Source object.
Return values
staticcreateFromText()
Creates Date object from Text (return array of result object) Examples: "end of next week", "tomorrow morning", "friday 25.10"
public
static createFromText(string $text) : DateTime|null
Parameters
- $text : string
Return values
DateTime|nullcreateFromTimestamp()
Creates DateTime object from Unix timestamp.
public
static createFromTimestamp(int $timestamp) : static
Parameters
- $timestamp : int
-
Source timestamp.
Return values
staticcreateFromUserTime()
Creates DateTime object from local user time using global timezone settings and default culture.
public
static createFromUserTime(string $timeString) : DateTime
Parameters
- $timeString : string
-
Full or short formatted time.
Return values
DateTimedisableUserTime()
public
disableUserTime() : $this
Return values
$thisenableUserTime()
public
enableUserTime() : $this
Return values
$thisformat()
Formats date value to string.
public
format(string $format) : string
Parameters
- $format : string
-
PHP date format.
Return values
stringgetDayOfWeek()
public
getDayOfWeek() : int
Return values
intgetDiff()
Returns difference between dates.
public
getDiff(Date $time) : DateInterval
Parameters
- $time : Date
Return values
DateIntervalgetFormat()
Returns a date format from the culture in the php format.
public
static getFormat([Culture|null $culture = null ]) : string
Parameters
- $culture : Culture|null = null
-
Optional culture.
Return values
stringgetTimestamp()
Returns Unix timestamp from date.
public
getTimestamp() : int
Return values
intgetTimeZone()
Returns timezone object.
public
getTimeZone() : DateTimeZone
Return values
DateTimeZoneisCorrect()
Checks the string for correct date (by trying to create Date object).
public
static isCorrect(string $time[, string $format = null ]) : bool
Parameters
- $time : string
-
String representation of date.
- $format : string = null
-
PHP date format. If not specified, the format is got from the current culture.
Return values
boolisUserTimeEnabled()
public
isUserTimeEnabled() : bool
Return values
boolsecondsToOffset()
public
static secondsToOffset(mixed $seconds[, mixed $delimiter = '' ]) : mixed
Parameters
- $seconds : mixed
- $delimiter : mixed = ''
setDate()
Sets the current date of the DateTime object to a different date.
public
setDate(int $year, int $month, int $day) : $this
Parameters
- $year : int
- $month : int
- $day : int
Return values
$thissetDefaultTimeZone()
Sets default timezone.
public
setDefaultTimeZone() : DateTime
Return values
DateTimesetTime()
public
setTime(int $hour, int $minute[, int $second = 0 ][, int $microseconds = 0 ]) : DateTime
Parameters
- $hour : int
-
Hour value.
- $minute : int
-
Minute value.
- $second : int = 0
-
Second value.
- $microseconds : int = 0
-
Microseconds value.
Return values
DateTimesetTimeZone()
Sets timezone object.
public
setTimeZone(DateTimeZone $timezone) : DateTime
Parameters
- $timezone : DateTimeZone
-
Timezone object.
Return values
DateTimetoPhp()
public
toPhp() : DateTime
Return values
DateTimetoString()
Converts date to string, using Culture and global timezone settings.
public
toString([Culture|null $culture = null ]) : string
Parameters
- $culture : Culture|null = null
-
Culture contains datetime format.
Return values
stringtoUserTime()
Changes time from server time to user time using global timezone settings.
public
toUserTime() : DateTime
Return values
DateTimetryParse()
Creates DateTime object from string.
public
static tryParse(string $timeString[, string $format = null ]) : DateTime|null
NULL will be returned on failure.
Parameters
- $timeString : string
-
Full formatted time.
- $format : string = null
-
PHP datetime format. If not specified, the format is got from the current culture.
Return values
DateTime|nullwithAdd()
public
withAdd(mixed $interval) : static
Parameters
- $interval : mixed
Return values
staticwithAddSeconds()
public
withAddSeconds(int $seconds) : static
Parameters
- $seconds : int
Return values
staticwithDate()
public
withDate(mixed $year, mixed $month, mixed $day) : static
Parameters
- $year : mixed
- $month : mixed
- $day : mixed
Return values
staticwithTime()
public
withTime(mixed $hour, mixed $minute[, mixed $second = 0 ][, mixed $microseconds = 0 ]) : static
Parameters
- $hour : mixed
- $minute : mixed
- $second : mixed = 0
- $microseconds : mixed = 0
Return values
staticwithTimeZone()
public
withTimeZone(DateTimeZone $timezone) : static
Parameters
- $timezone : DateTimeZone