日期格式 PHP WordPress 循环



我需要在下面的WordPress PHP循环中格式化日期输出。

当前输出如下所示:2019-07-10 12:00:00

我希望它看起来像这样:2019年7月10日(不需要时间(

<?php       
    $event_query = new WP_Query(
        array(
        'post_type' => 'tribe_events',               
        'order' => 'asc',
        'posts_per_page' => 2,                                        
        ) //end array 
    ); ?>
    <?php while ($event_query->have_posts()) : $event_query->the_post(); ?>
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <?php
        $meta_print_value=get_post_meta(get_the_ID(),'_EventStartDate',true);
        echo($meta_print_value);
        ?>
        <?php the_excerpt(); ?>
        <?php the_permalink(); ?>">View Event</a>
    <?php endwhile; wp_reset_query(); ?>

我已经尝试了几种技术,但无法使PHP恰到好处。

您可以使用 PHP 的内置日期函数格式化日期,请参阅文档以了解所有可能性。

以下是您希望实现的目标:

date('F, jS, Y', strtotime($wp_date));

小提琴:

https://3v4l.org/WOCPd

$meta_print_value后使用以下共享代码:

$meta_val=date('F,S,Y',strtotime($meta_print_value));

同时将echo($meta_print_value);替换为echo $meta_val;

最新更新