DateTime::format

DateTimeImmutable::format

DateTimeInterface::format

date_format

(PHP 5 >= 5.2.1, PHP 7)

DateTime::format -- DateTimeImmutable::format -- DateTimeInterface::format -- date_formatReturns date formatted according to given format

˵��

���������

public DateTime::format ( string $format ) : string
public DateTimeImmutable::format ( string $format ) : string
public DateTimeInterface::format ( string $format ) : string

���̻����

date_format ( DateTimeInterface $object , string $format ) : string

Returns date formatted according to given format.

����

object

��Ϊ���̻������ date_create() ���ص� DateTime ���͵Ķ���

format

Format accepted by date().

����ֵ

Returns the formatted date string on success ������ʧ��ʱ���� FALSE.

����

Example #1 DateTime::format() example

���������

<?php
$date 
= new DateTime('2000-01-01');
echo 
$date->format('Y-m-d H:i:s');
?>

���̻����

<?php
$date 
date_create('2000-01-01');
echo 
date_format($date'Y-m-d H:i:s');
?>

�������̻������

2000-01-01 00:00:00

ע��

This method does not use locales. All output is in English.

�μ�

  • date() - ��ʽ��һ������ʱ�䣯����