Format a date string in PHP

后端 未结 4 1452
渐次进展
渐次进展 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:32

    I would use strtotime AND strftime. Is a much simpler way of doing it.

    By example, if a have a date string like "Oct 20 18:29:50 2001 GMT" and I want to get it in format day/month/year I could do:

    $mystring = "Oct 20 18:29:50 2001 GMT";
    printf("Original string: %s\n", $mystring);
    $newstring = strftime("%d/%m/%Y", strtotime($mystring));
    printf("Data in format day/month/year is: %s\n", $newstring);
    

提交回复
热议问题