Correct input values of strtotime

前端 未结 3 739
自闭症患者
自闭症患者 2021-01-26 11:17

I want to convert a date by the following statement

$date=date(\'d M Y, H:m\',strtotime($date));

It printed out 09 Sep 2012, 11:09

相关标签:
3条回答
  • 2021-01-26 11:23

    Looks like the only way to go is to sort the elements in proper order by regular expressions and then replace the month name by corresponding number. Such a string strtotime will manage. Note: I'm talking about PHP 5.2x

    EDIT: I found the reason, why strtotime "wasn't working" was that I made a typo in the date formating string, there should be 'd M Y, H:i'

    0 讨论(0)
  • 2021-01-26 11:30

    Valid formats for strtotime are detailed here.

    0 讨论(0)
  • 2021-01-26 11:41

    From this site (http://www.tuxradar.com/practicalphp/4/5/2)

    Be wary of dates such as this one: August 25, 2003, 10:26am. Although this may look perfectly well-formed, strtotime() is not able to handle it because it has commas in there - yes, they make it much more readable for us, but strtotime() gets confused handling them. If you have dates with commas in, be sure to strip them out using str_replace().

    How to deal with strtotime() -> http://www.w3schools.com/php/func_date_strtotime.asp

    0 讨论(0)
提交回复
热议问题