PHP date formatting

后端 未结 3 1610
一向
一向 2020-12-19 11:52

I want to transform a date from this format: 01/07/09 to this jan 07,09.

How can I do that in PHP?

3条回答
  •  不知归路
    2020-12-19 12:39

    Use strptime to parse the value you've got, then date to output it in the format you want:

    echo date("M d,y", strptime("01/07/09", "d/m/y"));
    

    If you're on Windows, or using a version of PHP where strptime is not available (< PHP 5.1.0), then use strtotime instead, but be careful to make sure your date is in a US English format (i.e. "01/07/09" means January 7th 2009, not 1st July 2009).

    Also, if you really want jan, rather than Jan, then use strtolower:

    echo strtolower(date("M d,y", strptime("01/07/09", "d/m/y"));
    

提交回复
热议问题