How to convert yyyy-MM-dd HH:mm:ss to “15th Apr 2010” using PHP

后端 未结 3 1314
南方客
南方客 2021-01-12 02:19

I have the following date format: 2010-04-15 23:59:59

How would I go about converting this into: 15th Apr 2010

Thanks

相关标签:
3条回答
  • 2021-01-12 03:11
    $date = date("dS M Y",strtotime("2010-04-15 23:59:59"));
    
    print $date;
    
    0 讨论(0)
  • 2021-01-12 03:13
    echo date("jS M Y",strtotime("2010-04-15 23:59:59"));
    
    0 讨论(0)
  • 2021-01-12 03:15

    In addition to using date and strtotime, you can do

    $dateTime = new DateTime('2010-04-15 23:59:59');
    echo $dateTime->format('jS M Y'); // 15th Apr 2010
    

    or

    $dateTime = date_create('2010-04-15 23:59:59');
    echo date_format($dateTime, 'jS M Y'); // 15th Apr 2010
    
    0 讨论(0)
提交回复
热议问题