添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search
(current page)
Focus search box
public DateTimeInterface::format ( string $format ): string
public DateTimeImmutable::format ( string $format ): string
public DateTime::format ( string $format ): string

过程化风格

按照指定格式返回格式化后的日期。

面向对象风格

<?php
$date
= new DateTimeImmutable ( '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

示例 #2 更多示例

<?php
// 设置使用的默认时区。
date_default_timezone_set ( 'UTC' );

// 现在
$date = new DateTimeImmutable ();

// 打印类似:Wednesday
echo $date -> format ( 'l' ), "\n" ;

// 打印类似:Wednesday 19th of October 2022 08:40:48 AM
echo $date -> format ( 'l jS \o\f F Y h:i:s A' ), "\n" ;

/* 在 format 参数中使用常量 */
// 打印类似:Wed, 19 Oct 2022 08:40:48 +0000
echo $date -> format ( DateTimeInterface :: RFC2822 ), "\n" ;
?>