Bitrix API

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
throws
ObjectException

__toString()

Converts a date to the string with default culture format setting.

public __toString() : string
Return values
string

add()

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
$this

clone()

public clone() : static
Return values
static

convertFormatToPhp()

Converts date format from culture to php format.

public static convertFormatToPhp(string $format) : string
Parameters
$format : string

Format string.

Return values
string

createFromFormat()

public static createFromFormat(string $format, string $dateTime) : self
Parameters
$format : string
$dateTime : string
Return values
self

createFromMainDateTime()

public static createFromMainDateTime(DateTime $dateTime) : static
Parameters
$dateTime : DateTime
Return values
static

createFromMainDateTimeOrNull()

public static createFromMainDateTimeOrNull(DateTime|null $dateTime) : static|null
Parameters
$dateTime : DateTime|null
Return values
static|null

createFromPhp()

Creates DateTime object from PHP \DateTime object.

public static createFromPhp(DateTime $datetime) : static
Parameters
$datetime : DateTime

Source object.

Return values
static

createFromText()

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|null

createFromTimestamp()

Creates DateTime object from Unix timestamp.

public static createFromTimestamp(int $timestamp) : static
Parameters
$timestamp : int

Source timestamp.

Return values
static

createFromUserTime()

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
DateTime

disableUserTime()

public disableUserTime() : $this
Return values
$this

enableUserTime()

public enableUserTime() : $this
Return values
$this

format()

Formats date value to string.

public format(string $format) : string
Parameters
$format : string

PHP date format.

Return values
string

getDayOfWeek()

public getDayOfWeek() : int
Return values
int

getDiff()

Returns difference between dates.

public getDiff(Date $time) : DateInterval
Parameters
$time : Date
Return values
DateInterval

getFormat()

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
string

getTimestamp()

Returns Unix timestamp from date.

public getTimestamp() : int
Return values
int

getTimeZone()

Returns timezone object.

public getTimeZone() : DateTimeZone
Return values
DateTimeZone

isCorrect()

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
bool

isUserTimeEnabled()

public isUserTimeEnabled() : bool
Return values
bool

secondsToOffset()

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
$this

setTime()

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
DateTime

setTimeZone()

Sets timezone object.

public setTimeZone(DateTimeZone $timezone) : DateTime
Parameters
$timezone : DateTimeZone

Timezone object.

Return values
DateTime

toPhp()

public toPhp() : DateTime
Return values
DateTime

toString()

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
string

toUserTime()

Changes time from server time to user time using global timezone settings.

public toUserTime() : DateTime
Return values
DateTime

tryParse()

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|null

withAdd()

public withAdd(mixed $interval) : static
Parameters
$interval : mixed
Return values
static

withAddSeconds()

public withAddSeconds(int $seconds) : static
Parameters
$seconds : int
Return values
static

withDate()

public withDate(mixed $year, mixed $month, mixed $day) : static
Parameters
$year : mixed
$month : mixed
$day : mixed
Return values
static

withTime()

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
static

withTimeZone()

public withTimeZone(DateTimeZone $timezone) : static
Parameters
$timezone : DateTimeZone
Return values
static

        
On this page

Search results