PHP strtotime problems with minutes [closed]

杀马特。学长 韩版系。学妹 提交于 2020-01-10 05:43:07

问题


Is that normal that this line:

echo date("Y-m-d h:m:s a", strtotime('2012-03-18 12:55:00'))

gives me 2012-03-18 12:03:00 pm

Whatever the minutes I enter, I always get 03 minutes... weird.


回答1:


Your date string format should be :

Y-m-d h:i:s a

PHP's documentation has this to say about formatting a local time/date -

  • i - Minutes with leading zeros
  • m - Numeric representation of a month, with leading zeros

What you were seeing as 03 was actually the month - March :)




回答2:


That's because m in the date function represents months, not minutes. For minutes, you want to use i:

Y-m-d h:i:s a



回答3:


In PHP's date function, the code for minutes is i not m:

echo date("Y-m-d h:i:s a", strtotime('2012-03-18 12:55:00'))



回答4:


Your "minutes" are actually "months". Use i as your date code:

echo date("Y-m-d h:i:s a", strtotime('2012-03-18 12:55:00'))


来源:https://stackoverflow.com/questions/9759720/php-strtotime-problems-with-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!