2019-04-18 11:11
采纳率: 0%
浏览 122

如何在PHP中将日期转换为字符串日期? [重复]

This question already has an answer here:

I am trying to convert a date '2019-04-18' to something like this '18 Apr 2019' in php.

echo date_format($date,'jS F Y');

It is giving me output like this :

18th April 2019

But i need output to be '18 Apr 2019' ie: 3 letters of month


图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 在PHP中将一种日期格式转换为另一种格式 15 answers < / span>

    我正在尝试将日期'2019-04-18'转换为某种东西 喜欢这个'201年4月18日'在php。

      $ date = date_create(“2019-04-18”); 
    echo date_format($ date,'jS F Y'  ); 



    但我需要输出为'201 Apr 2019'即:3个月的字母

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dounue1965 2019-04-18 11:12

    You need to use M here for month and d for day:

    echo date_format($date,'d M Y'); // 18 Apr 2019

    According to PHP Manual:

    d => Day of the month, 2 digits with leading zeros (e.g 01 to 31)

    M => A short textual representation of a month, three letters (e.g Jan through Dec)

    解决 无用
    打赏 举报
  • dousi6405 2019-04-18 11:13

    You just need to tune date formatting like below,

    echo date_format($date,'d M Y');

    for more details or the link from where I created this format is here.

    解决 无用
    打赏 举报
  • douchun1859 2019-04-18 11:14

    Instead of F and jS you need to use d and M

    echo date_format($date,'d M Y'); 

    The above script will print following output

    // 18 Apr 2019
    解决 无用
    打赏 举报
  • doukengzi3517 2019-04-18 11:16
    echo date_format($date,'jS M Y');
    echo "<br>";
    echo date_format($date,'j M Y');
    解决 无用
    打赏 举报

相关推荐 更多相似问题