\OCPIDateTimeFormatter

Interface IDateTimeFormatter

Summary

Methods
Constants
formatDate()
formatDateRelativeDay()
formatDateSpan()
formatTime()
formatTimeSpan()
formatDateTime()
formatDateTimeRelativeDay()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

formatDate()

formatDate(integer|\DateTime  $timestamp, string  $format = 'long', \DateTimeZone  $timeZone = null, \OCP\IL10N  $l = null) : string

Formats the date of the given timestamp

Parameters

integer|\DateTime $timestamp
string $format

Either 'full', 'long', 'medium' or 'short' full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' long: e.g. 'MMMM d, y' => 'August 20, 2014' medium: e.g. 'MMM d, y' => 'Aug 20, 2014' short: e.g. 'M/d/yy' => '8/20/14' The exact format is dependent on the language

\DateTimeZone $timeZone

The timezone to use

\OCP\IL10N $l

The locale to use

Returns

string —

Formatted date string

formatDateRelativeDay()

formatDateRelativeDay(integer|\DateTime  $timestamp, string  $format = 'long', \DateTimeZone  $timeZone = null, \OCP\IL10N  $l = null) : string

Formats the date of the given timestamp

Parameters

integer|\DateTime $timestamp
string $format

Either 'full', 'long', 'medium' or 'short' full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' long: e.g. 'MMMM d, y' => 'August 20, 2014' medium: e.g. 'MMM d, y' => 'Aug 20, 2014' short: e.g. 'M/d/yy' => '8/20/14' The exact format is dependent on the language Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable

\DateTimeZone $timeZone

The timezone to use

\OCP\IL10N $l

The locale to use

Returns

string —

Formatted relative date string

formatDateSpan()

formatDateSpan(integer|\DateTime  $timestamp, integer|\DateTime  $baseTimestamp = null, \OCP\IL10N  $l = null) : string

Gives the relative date of the timestamp Only works for past dates

Parameters

integer|\DateTime $timestamp
integer|\DateTime $baseTimestamp

Timestamp to compare $timestamp against, defaults to current time

\OCP\IL10N $l

The locale to use

Returns

string —

Dates returned are: < 1 month => Today, Yesterday, n days ago < 13 month => last month, n months ago

= 13 month => last year, n years ago

formatTime()

formatTime(integer|\DateTime  $timestamp, string  $format = 'medium', \DateTimeZone  $timeZone = null, \OCP\IL10N  $l = null) : string

Formats the time of the given timestamp

Parameters

integer|\DateTime $timestamp
string $format

Either 'full', 'long', 'medium' or 'short' full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00' long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT' medium: e.g. 'h:mm:ss a' => '11:42:13 AM' short: e.g. 'h:mm a' => '11:42 AM' The exact format is dependent on the language

\DateTimeZone $timeZone

The timezone to use

\OCP\IL10N $l

The locale to use

Returns

string —

Formatted time string

formatTimeSpan()

formatTimeSpan(integer|\DateTime  $timestamp, integer|\DateTime  $baseTimestamp = null, \OCP\IL10N  $l = null) : string

Gives the relative past time of the timestamp

Parameters

integer|\DateTime $timestamp
integer|\DateTime $baseTimestamp

Timestamp to compare $timestamp against, defaults to current time

\OCP\IL10N $l

The locale to use

Returns

string —

Dates returned are: < 60 sec => seconds ago < 1 hour => n minutes ago < 1 day => n hours ago < 1 month => Yesterday, n days ago < 13 month => last month, n months ago

= 13 month => last year, n years ago

formatDateTime()

formatDateTime(integer|\DateTime  $timestamp, string  $formatDate = 'long', string  $formatTime = 'medium', \DateTimeZone  $timeZone = null, \OCP\IL10N  $l = null) : string

Formats the date and time of the given timestamp

Parameters

integer|\DateTime $timestamp
string $formatDate

See formatDate() for description

string $formatTime

See formatTime() for description

\DateTimeZone $timeZone

The timezone to use

\OCP\IL10N $l

The locale to use

Returns

string —

Formatted date and time string

formatDateTimeRelativeDay()

formatDateTimeRelativeDay(integer|\DateTime  $timestamp, string  $formatDate = 'long', string  $formatTime = 'medium', \DateTimeZone  $timeZone = null, \OCP\IL10N  $l = null) : string

Formats the date and time of the given timestamp

Parameters

integer|\DateTime $timestamp
string $formatDate

See formatDate() for description Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable

string $formatTime

See formatTime() for description

\DateTimeZone $timeZone

The timezone to use

\OCP\IL10N $l

The locale to use

Returns

string —

Formatted relative date and time string