Bitrix API

DateTime extends DateTime

FinalYes

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.
addDay()  : mixed
addHour()  : mixed
addMinute()  : mixed
addSecond()  : mixed
checkGT()  : mixed
checkInRange()  : mixed
checkLT()  : mixed
convertFormatToPhp()  : string
Converts date format from culture to php format.
convertToGmt()  : mixed
convertToLocalTime()  : mixed
createFrom()  : mixed
createFromDateTime()  : self
createFromInstance()  : mixed
createFromObjectOrString()  : mixed
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.
createFromTimestampGmt()  : mixed
$unix is treated as GMT time stamp, e.g. 1445337000 is "Tue, 20 Oct 2015 10:30:00 GMT", but NOT "10/20/2015 12:30:00 PM GMT+2:00 DST"
createFromTimeStruct()  : mixed
$dateTime is treated as local datetime struct
createFromTimeStructGmt()  : mixed
$dateTime is treated as GMT datetime struct
createFromUserTime()  : DateTime
$timeString is treated as local datetime string
createFromUserTimeGmt()  : mixed
$timeString treated as a GMT, i.e. with time zone offset equals to zero Actually, this method should be called like createFromTimeStringGmt, user time has no relation with that
disableUserTime()  : $this
enableUserTime()  : $this
format()  : string
Formats date value to string.
getCurrentTimestamp()  : int
getCurrentTimeString()  : string
getDay()  : int
getDayGmt()  : mixed
getDefaultTimeZone()  : mixed
getDiff()  : DateInterval
Returns difference between dates.
getFormat()  : string
Returns a date format from the culture in the php format.
getHour()  : int
getHourGmt()  : mixed
getInfoGmt()  : mixed
This function is for debug purposes only
getMinute()  : int
getMinuteGmt()  : mixed
getMonth()  : int
getMonthGmt()  : mixed
getSecondGmt()  : mixed
getTimestamp()  : int
Returns Unix timestamp from date.
getTimeStruct()  : mixed
getTimeStructGmt()  : mixed
getTimeZone()  : DateTimeZone
Returns timezone object.
getWeekDay()  : int
getWeekDayGmt()  : mixed
getYear()  : int
getYearGmt()  : mixed
isCorrect()  : bool
Checks the string for correct date (by trying to create Date object).
isEqualTo()  : mixed
isNotEqualTo()  : mixed
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.
stripSeconds()  : mixed
stripTime()  : mixed
todo: the better way would be like in
toString()  : string
Converts date to string, using Culture and global timezone settings.
toStringGmt()  : mixed
toUserTime()  : DateTime
Changes time from server time to user time using global timezone settings.
tryParse()  : DateTime|null
Creates DateTime object from string.

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

addDay()

public addDay(mixed $offset) : mixed
Parameters
$offset : mixed

addHour()

public addHour(mixed $offset) : mixed
Parameters
$offset : mixed

addMinute()

public addMinute(mixed $offset) : mixed
Parameters
$offset : mixed

addSecond()

public addSecond(mixed $offset) : mixed
Parameters
$offset : mixed

checkGT()

public checkGT(DateTime $date[, mixed $strict = true ]) : mixed
Parameters
$date : DateTime
$strict : mixed = true

checkInRange()

public checkInRange([mixed $start = null ][, mixed $end = null ]) : mixed
Parameters
$start : mixed = null
$end : mixed = null

checkLT()

public checkLT(DateTime $date[, mixed $strict = true ]) : mixed
Parameters
$date : DateTime
$strict : mixed = true

convertFormatToPhp()

Converts date format from culture to php format.

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

Format string.

Return values
string

convertToGmt()

public convertToGmt() : mixed

convertToLocalTime()

public convertToLocalTime() : mixed

createFrom()

public static createFrom(mixed $time[, mixed $offset = null ]) : mixed
Parameters
$time : mixed
$offset : mixed = null

createFromDateTime()

public static createFromDateTime(DateTime $dateTime) : self
Parameters
$dateTime : DateTime
Return values
self

createFromObjectOrString()

public static createFromObjectOrString(mixed $value) : mixed
Parameters
$value : mixed

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

createFromTimestampGmt()

$unix is treated as GMT time stamp, e.g. 1445337000 is "Tue, 20 Oct 2015 10:30:00 GMT", but NOT "10/20/2015 12:30:00 PM GMT+2:00 DST"

public static createFromTimestampGmt(mixed $unix) : mixed
Parameters
$unix : mixed

createFromTimeStruct()

$dateTime is treated as local datetime struct

public static createFromTimeStruct(array<string|int, mixed> $dateTime[, mixed $monthZeroBase = false ]) : mixed
Parameters
$dateTime : array<string|int, mixed>
$monthZeroBase : mixed = false

createFromTimeStructGmt()

$dateTime is treated as GMT datetime struct

public static createFromTimeStructGmt(array<string|int, mixed> $dateTime[, mixed $monthZeroBase = false ]) : mixed
Parameters
$dateTime : array<string|int, mixed>
$monthZeroBase : mixed = false

createFromUserTime()

$timeString is treated as local datetime string

public static createFromUserTime(mixed $timeString) : DateTime
Parameters
$timeString : mixed

Full or short formatted time.

Return values
DateTime

createFromUserTimeGmt()

$timeString treated as a GMT, i.e. with time zone offset equals to zero Actually, this method should be called like createFromTimeStringGmt, user time has no relation with that

public static createFromUserTimeGmt(mixed $timeString) : mixed
Parameters
$timeString : mixed

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

getCurrentTimestamp()

public static getCurrentTimestamp() : int
Return values
int

getCurrentTimeString()

public static getCurrentTimeString() : string
Return values
string

getDay()

public getDay() : int
Return values
int

getDefaultTimeZone()

public static getDefaultTimeZone() : mixed

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

getHour()

public getHour() : int
Return values
int

getHourGmt()

public getHourGmt() : mixed

getInfoGmt()

This function is for debug purposes only

public getInfoGmt() : mixed
Tags
access

private

getMinute()

public getMinute() : int
Return values
int

getMinuteGmt()

public getMinuteGmt() : mixed

getMonth()

public getMonth([bool $zeroBase = false ]) : int
Parameters
$zeroBase : bool = false
Return values
int

getMonthGmt()

public getMonthGmt([mixed $zeroBase = false ]) : mixed
Parameters
$zeroBase : mixed = false

getSecondGmt()

public getSecondGmt() : mixed

getTimestamp()

Returns Unix timestamp from date.

public getTimestamp() : int
Return values
int

getTimeStruct()

public getTimeStruct([mixed $monthZeroBase = false ]) : mixed
Parameters
$monthZeroBase : mixed = false

getTimeStructGmt()

public getTimeStructGmt([mixed $monthZeroBase = false ]) : mixed
Parameters
$monthZeroBase : mixed = false

getTimeZone()

Returns timezone object.

public getTimeZone() : DateTimeZone
Return values
DateTimeZone

getWeekDay()

public getWeekDay() : int
Return values
int

getWeekDayGmt()

public getWeekDayGmt() : mixed

getYear()

public getYear() : int
Return values
int

getYearGmt()

public getYearGmt() : mixed

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

stripSeconds()

public stripSeconds() : mixed

stripTime()

todo: the better way would be like in

public stripTime() : mixed
Tags
see
Task::getDayStartDateTime()

test for both local and gmt dates.

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

toStringGmt()

public toStringGmt() : mixed

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

        
On this page

Search results