PHP Date - How to add a string to separate date and time

后端 未结 5 1198
我寻月下人不归
我寻月下人不归 2021-01-13 01:19

I want to display date and time format something like this \"May 23 at 12:30pm\". I saw in PHP manual and found:

// Prints something like: Monda         


        
相关标签:
5条回答
  • 2021-01-13 01:30

    You need to escape the t too:

    echo date('M j \a\t h:i a');
    
    0 讨论(0)
  • 2021-01-13 01:34

    You need to try this in php:

    $t = now(); //This will give you current time
    echo date_format($t,"dS M,y \a\\t h:i a"); //14th May,19 at 05:39am
    
    0 讨论(0)
  • 2021-01-13 01:47

    you need to escape the a and t as both have special meaning when used as formatting options in date()

    echo date('M j \a\t h:i a');
    

    See it in action

    0 讨论(0)
  • 2021-01-13 01:47

    Try

    <?php
        echo date('M j \a\t h:i a');
    ?>
    

    OR

    <?php
        echo date('M j'). "at". date(' h:i a');
    ?>
    
    0 讨论(0)
  • 2021-01-13 01:47

    Another option could be:

    echo date('M j')." at ".date('h:i a');
    
    0 讨论(0)
提交回复
热议问题