PHP Date解析成新格式

Roy*_*ber -4 php

我有一个打印出来的功能:

echo $post->EE_Event->primary_datetime()->start_date_and_time();
Run Code Online (Sandbox Code Playgroud)

结果:

21-02-15 08:00
Run Code Online (Sandbox Code Playgroud)

但我想将其显示为:

08:00 21st February, 2015
Run Code Online (Sandbox Code Playgroud)

我需要一个函数帮助来获取现有的打印日期并重新格式化.

我在线尝试了几个片段,但没有任何效果.

ajt*_*tek 6

试试这段代码:

$yourDate = '21-02-15 08:00'; // $post->EE_Event->primary_datetime()->start_date_and_time()
$date = DateTime::createFromFormat('j-m-y G:i', $yourDate);
echo $date->format('G:i dS F, Y');
Run Code Online (Sandbox Code Playgroud)

在线试用:http: //ideone.com/a7EEK4

在PHP> = 5.3中,我们拥有出色的日期API.在此处查看更多信息:http: //php.net/manual/en/datetime.createfromformat.php