yii\i18n\Formatter::asDate PHP Method

asDate() public method

Formats the value as a date.
See also: dateFormat
public asDate ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[dateFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
return string the formatted result.
    public function asDate($value, $format = null)
    {
        if ($format === null) {
            $format = $this->dateFormat;
        }
        return $this->formatDateTimeValue($value, $format, 'date');
    }

Usage Example

Exemplo n.º 1
0
 public function testDate()
 {
     $time = time();
     $this->assertSame(date('n/j/y', $time), $this->formatter->asDate($time));
     $this->assertSame(date('F j, Y', $time), $this->formatter->asDate($time, 'long'));
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asDate(null));
 }
All Usage Examples Of yii\i18n\Formatter::asDate