DateFormatterInterface
interface DateFormatterInterface (View source)
Provides an interface defining a date formatter.
Methods
Formats a date, using a date type or a custom date format string.
Formats a time interval with the requested granularity.
Provides values for all date formatting characters for a given timestamp.
Formats the time difference from the current request time to a timestamp.
Formats the time difference from a timestamp to the current request time.
Formats a time interval between two timestamps.
Details
string
format(int $timestamp, string $type = 'medium', string $format = '', string|null $timezone = NULL, string|null $langcode = NULL)
Formats a date, using a date type or a custom date format string.
string
formatInterval(int $interval, int $granularity = 2, string|null $langcode = NULL)
Formats a time interval with the requested granularity.
Note that for intervals over 30 days, the output is approximate: a "month" is always exactly 30 days, and a "year" is always 365 days. It is not possible to make a more exact representation, given that there is only one input in seconds. If you are formatting an interval between two specific timestamps, use \Drupal\Core\Datetime\DateFormatter::formatDiff() instead.
array
getSampleDateFormats(string|null $langcode = NULL, int|null $timestamp = NULL, string|null $timezone = NULL)
Provides values for all date formatting characters for a given timestamp.
string|FormattedDateDiff
formatTimeDiffUntil($timestamp, array $options = [])
Formats the time difference from the current request time to a timestamp.
string|FormattedDateDiff
formatTimeDiffSince($timestamp, array $options = [])
Formats the time difference from a timestamp to the current request time.
string|FormattedDateDiff
formatDiff(int $from, int $to, array $options = [])
Formats a time interval between two timestamps.