开发者

Wrong output from date()

I am getting the date from my MySQL database and that date is correct, but when I use the date() fun开发者_JAVA技巧ction the minute part is stuck at 6 minutes.

MySQL is returning 2010-06-15 09:59:18

Then in PHP I use this code ($row[4] is from my while loop):

date('M d,Y H:m A',strtotime($row[4]))

When I echo this out I get: Jun 15,2010 9:06 AM

I also have tried converting it to a unix timestamp in my SQL query, but it does the same thing. I noticed that the hours work and the seconds work but the minutes are stuck at 6. Does anyone have any ideas on what is going on?


'm' is a representation of month, not minutes using the PHP date() function. So, you are getting the '06', meaning June, not 06 minutes past 9.

It only looks like minutes because of how you formatted your date string but what you are getting there is a numerical representation of the month.


http://us2.php.net/manual/en/function.date.php

m - Numeric representation of a month, with leading zeros


I think the minute arg should be i (lowercase eye), not m.


Use this instead (i instead of m):

date('M d,Y H:i A',strtotime($row[4]))


The capital m is the month, and now it's June ;) The minute is "i"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜