string date_format ( DateTime $object, string $format ) string DateTime::format ( string $format )
这些函数返回根据给定格式化的日期,上述两个函数是等效的,并且可以使用任何函数,如下例所示。
object - DateTime对象
format - 时间格式化
d - the day of the Month(从01到31)
D - 一天的文本表示(三个字母)
j - 不带前导零的月份日期(1到31)
l(小写‘L') - 一天的完整文本表示
N - 一天的ISO-8601数字表示(1表示星期一到7表示星期日)
S - 当月某天的英文序号后缀(2个字符st,nd,rd或th。与j配合得很好)
w - 一天的数字表示(0表示星期日,6表示星期六)
z - 一年中的某一天(从0到365)
W - 国际标准化组织-8601一年中的周数(从星期一开始的周数)
F - 一个月的完整文本表示(1月到12月)
m - 月份的数字表示(从01到12)
M - 一个月的简短文本表示(三个字母)
n - 月份的数字表示,不带前导零(1到12)
t - 给定月份中的天数
L - 是否为闰年(如果是闰年,则为1,否则为0)
o - ISO-8601年份编号
Y一年的四位数表示法
y-一年的两位数表示
a-小写am或pm
A-AM或PM
B-Swatch互联网时间(000年至999年)
g-一小时的12小时格式(1到12)
G-一小时的24小时格式(0到23)
h-一小时的12小时格式(01至12)
H-一小时的24小时格式(00至23)
i-带有前导零的I-分钟(00到59)
s-秒,带有前导零(00到59)
e - The timezone identifier (示例s: UTC, Atlantic/Azores)
I(大写i)-日期是否采用夏令时(如果是夏令时,则为1,否则为0)
O - Difference to Greenwich time (GMT) in hours (示Example: +0100)
T - Timezone setting of the PHP machine (示例s: EST, MDT)
Z-时区偏移量(秒)。协调世界时西部的偏移为负,协调世界时东部的偏移为正(-43200到43200)
c-ISO-8601日期(例如2004-02-12T15:19:21+00:00)
链接:https://www.learnfk.comhttps://www.learnfk.com/php/php-function-date-format.html
来源:LearnFk无涯教程网
r-RFC2822格式化日期(例如,2000年12月21日星期四16:01:07+0200)
U-自unix纪元以来的秒数(1970年1月1日00:00:00GMT)
成功时返回格式化日期,失败时返回False。
<?php $dateSrc='2005-04-19 12:50 GMT'; $dateTime=date_create( $dateSrc);; # Now set a new date using date_format(); date_format( $dateTime, 2000, 12, 12); echo "New Formatted date is ". $dateTime->format("Y-m-d\TH:i:s\Z"); echo "<br />"; # Using second function. $dateTime=new DateTime($dateSrc); $dateTime->setDate( 1999, 10, 12); echo "New Formatted date is ". $dateTime->format("Y-m-d\TH:i:s\Z"); ?>
这将产生以下输出-
New Formatted date is 2000-12-12T12:50:00Z New Formatted date is 1999-10-12T12:50:00Z
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)