最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - How to break a date from ACF?

programmeradmin0浏览0评论

I need to print the number in one font, and the year in another

 <?php $timestamp = get_field('date_time'); ?>

How to do it . help me please

I need to print the number in one font, and the year in another

 <?php $timestamp = get_field('date_time'); ?>

How to do it . help me please

Share Improve this question edited Sep 3, 2019 at 10:27 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Sep 3, 2019 at 6:45 KaizerKaizer 111 bronze badge 2
  • Welcome to WPSE. For formatting dates and times you can find examples in the PHP date() documentation, php/manual/en/function.date.php. And please note that 3rd party plugins, such as ACF, are considered off-topic here on WPSE. It is highly recommended to contact the plugin author should you have any questions regarding the use and/or configuration of the plugin. – Antti Koskinen Commented Sep 3, 2019 at 9:14
  • thank you very match)))) – Kaizer Commented Sep 3, 2019 at 11:34
Add a comment  | 

1 Answer 1

Reset to default 0

Here you can get separated data from timestamp using date(); function. you can apply different fonts each value.

 <?php 
    $timestamp = get_field('date_time');

    $day = date('d', $timestamp);
    $mon = date('m', $timestamp);
    $year = date('Y', $timestamp);

    echo "Day : ".$day."<br>";
    echo "Month : ".$mon."<br>";
    echo "Year : ".$year;
?>

if $timestamp value "1567503270" then output will be below.

Output :

Day : 03
Month : 09
Year : 2019

if get_field('date_time') return 15 june, 2019 then its timestap will be 1560629940. see below code for reference.

$timestamp = strtotime("15 june, 2019");

$day = date('d', $timestamp);
$mon = date('m', $timestamp);
$year = date('Y', $timestamp);

echo "timestamp : ".$timestamp."<br>";
echo "Day : ".$day."<br>";
echo "Month : ".$mon."<br>";
echo "Year : ".$year;

**Output**

timestamp : 1560629940
Day : 15
Month : 06
Year : 2019
发布评论

评论列表(0)

  1. 暂无评论