如何回显正确的日期格式
How to echo out the correct date format
我在 WordPress 的 functions.php 文件中写了这个 add_action 片段。事件日期成功回显,但我正在努力寻找正确的最后一点代码,以便它以格式 ('d M Y') 回显。我现在刚得到基本日期字符串,即 20181225
谁能帮我完成这个,谢谢?
add_action( 'dfbm_post_meta_before', function( $post, $featured )
{
echo get_post_meta($post->ID,'event_date',true);
} , 10, 2 );
简单,使用PHP的日期时间
echo (new DateTime(get_post_meta($post->ID,'event_date',true)))->format('d M Y');
输出
echo (new DateTime('20181225'))->format('d M Y');
25 Dec 2018
使用简单的 date() 函数:
echo date('d M Y', '20181225');
我在 WordPress 的 functions.php 文件中写了这个 add_action 片段。事件日期成功回显,但我正在努力寻找正确的最后一点代码,以便它以格式 ('d M Y') 回显。我现在刚得到基本日期字符串,即 20181225
谁能帮我完成这个,谢谢?
add_action( 'dfbm_post_meta_before', function( $post, $featured )
{
echo get_post_meta($post->ID,'event_date',true);
} , 10, 2 );
简单,使用PHP的日期时间
echo (new DateTime(get_post_meta($post->ID,'event_date',true)))->format('d M Y');
输出
echo (new DateTime('20181225'))->format('d M Y');
25 Dec 2018
使用简单的 date() 函数:
echo date('d M Y', '20181225');