DateTimeFormatter

class OC\DateTimeFormatter
Source:lib/private/DateTimeFormatter.php#28
Implements:OCP\IDateTimeFormatter

Properties

protected static property OC\DateTimeFormatter::$defaultTimeZone
Source:lib/private/DateTimeFormatter.php#30
Type:\DateTimeZone
protected static property OC\DateTimeFormatter::$defaultL10N
Source:lib/private/DateTimeFormatter.php#33
Type:\OCP\IL10N

Methods

public OC\DateTimeFormatter::__construct($defaultTimeZone, $defaultL10N)
Constructor
Source:

lib/private/DateTimeFormatter.php#41

Parameters:
  • $defaultTimeZone (DateTimeZone) Set the timezone for the format
  • $defaultL10N (OCP\IL10N) Set the language for the format
protected OC\DateTimeFormatter::getTimeZone($timeZone=null)
Get TimeZone to use
Source:

lib/private/DateTimeFormatter.php#52

Parameters:
Returns:

\DateTimeZone The timezone to use, falling back to the current user’s timezone

protected OC\DateTimeFormatter::getLocale($l=null)
Get \OCP\IL10N to use
Source:

lib/private/DateTimeFormatter.php#66

Parameters:
Returns:

\OCP\IL10N The locale to use, falling back to the current user’s locale

protected OC\DateTimeFormatter::getDateTime($timestamp, $timeZone=null)
Generates a DateTime object with the given timestamp and TimeZone
Source:

lib/private/DateTimeFormatter.php#81

Parameters:
  • $timestamp (mixed)
  • $timeZone (DateTimeZone) The timezone to use
Returns:

\DateTime

public OC\DateTimeFormatter::formatDate($timestamp, $format=long, $timeZone=null, $l=null)
Formats the date of the given timestamp
Source:

lib/private/DateTimeFormatter.php#109

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $format (string) 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 * $timeZone (DateTimeZone) The timezone to use * $l (OCP\IL10N) The locale to use

Returns:

string Formatted date string

public OC\DateTimeFormatter::formatDateRelativeDay($timestamp, $format=long, $timeZone=null, $l=null)
Formats the date of the given timestamp
Source:

lib/private/DateTimeFormatter.php#128

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $format (string) 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

Returns:

string Formatted relative date string

public OC\DateTimeFormatter::formatDateSpan($timestamp, $baseTimestamp=null, $l=null)
Gives the relative date of the timestamp
Only works for past dates
Source:

lib/private/DateTimeFormatter.php#149

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $baseTimestamp (int | \DateTime) Timestamp to compare $timestamp against, defaults to current time
  • $l (OCP\IL10N) 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

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

public OC\DateTimeFormatter::formatTime($timestamp, $format=medium, $timeZone=null, $l=null)
Formats the time of the given timestamp
Source:

lib/private/DateTimeFormatter.php#215

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $format (string) 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 * $timeZone (DateTimeZone) The timezone to use * $l (OCP\IL10N) The locale to use

Returns:

string Formatted time string

public OC\DateTimeFormatter::formatTimeSpan($timestamp, $baseTimestamp=null, $l=null)
Gives the relative past time of the timestamp
Source:

lib/private/DateTimeFormatter.php#234

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $baseTimestamp (int | \DateTime) Timestamp to compare $timestamp against, defaults to current time
  • $l (OCP\IL10N) 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

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

public OC\DateTimeFormatter::formatDateTime($timestamp, $formatDate=long, $formatTime=medium, $timeZone=null, $l=null)
Formats the date and time of the given timestamp
Source:

lib/private/DateTimeFormatter.php#277

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $formatDate (string) See formatDate() for description
  • $formatTime (string) See formatTime() for description
  • $timeZone (DateTimeZone) The timezone to use
  • $l (OCP\IL10N) The locale to use
Returns:

string Formatted date and time string

public OC\DateTimeFormatter::formatDateTimeRelativeDay($timestamp, $formatDate=long, $formatTime=medium, $timeZone=null, $l=null)
Formats the date and time of the given timestamp
Source:

lib/private/DateTimeFormatter.php#292

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $formatDate (string) See formatDate() for description

Uses ‘Today’, ‘Yesterday’ and ‘Tomorrow’ when applicable * $formatTime (string) See formatTime() for description * $timeZone (DateTimeZone) The timezone to use * $l (OCP\IL10N) The locale to use

Returns:

string Formatted relative date and time string

protected OC\DateTimeFormatter::format($timestamp, $type, $format, $timeZone=null, $l=null)
Formats the date and time of the given timestamp
Source:

lib/private/DateTimeFormatter.php#310

Parameters:
  • $timestamp (int | \DateTime) Either a Unix timestamp or DateTime object
  • $type (string) One of ‘date’, ‘datetime’ or ‘time’
  • $format (string) Format string
  • $timeZone (DateTimeZone) The timezone to use
  • $l (OCP\IL10N) The locale to use
Returns:

string Formatted date and time string