如何从高级自定义字段自定义 "Date"

How to customize the "Date" from Advanced Custom Field

我需要在 Wordpress 中为网站制作议程。 我使用 ACF 作为日期,我想用跨度或 div 分隔日、月和年以更改日期的样式。

目前我有:

<?php the_field('jour_de_levenement'); ?>

日期出现了,但我无法 select 自定义日期。所以我尝试了类似的方法,但似乎没有用:

<?php $date = DateTime::createFromFormat('dFY', get_field('jour_de_levenement')); ?>
<span class="day"><?php echo $date->format('d'); ?></span>
<span class="month"><?php echo $date->format('F'); ?></span>
<span class="year"><?php echo $date->format('Y'); ?></span>

它给了我一个致命错误。

这是我想做的事情的图片: date-agenda

非常感谢!

来自此处的 ACF 文档:

https://www.advancedcustomfields.com/resources/date-picker/

我想出了这个代码,使用你的信息:

<?php // get raw date
$date = get_field('jour_de_levenement', false, false);
// make date object
$date = new DateTime($date); ?>
<span class="day"><?php echo $date->format('d'); ?></span>
<span class="month"><?php echo $date->format('F'); ?></span>
<span class="year"><?php echo $date->format('Y'); ?></span>

测试此代码时,我创建了一个日期字段,其中所有设置均为默认设置(特别是显示格式和 Return 格式选项)。 get_field() 中的第二个 false 消除了对 createFromFormat 函数中大部分代码的需要。