Format a date string in PHP

后端 未结 4 1457
渐次进展
渐次进展 2021-01-12 10:47

If I have a string which represents a date, like \"2011/07/01\" (which is 1st July 2011) , how would I output that in more readable forms, like:

1 July 201         


        
4条回答
  •  暖寄归人
    2021-01-12 11:30

    You can convert your date to a timestamp using strtotime() and then use date() on that timestamp. On your example:

    $date = date("j F Y", strtotime("2011/07/01")); // 1 July 2011
    $date = date("j M Y", strtotime("2011/07/01")); // 1 Jul 2011
    

提交回复
热议问题