简体   繁体   English

date()的输出错误

[英]Wrong output from date()

I am getting the date from my MySQL database and that date is correct, but when I use the date() function the minute part is stuck at 6 minutes. 我从MySQL数据库获取日期,该日期是正确的,但是当我使用date()函数时,分钟部分停留在6分钟。

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

Then in PHP I use this code ( $row[4] is from my while loop): 然后在PHP中,我使用以下代码( $row[4]来自我的while循环):

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

When I echo this out I get: Jun 15,2010 9:06 AM 当我回应时,我得到: 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. 我也曾尝试在SQL查询中将其转换为unix时间戳,但它具有相同的作用。 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? 我注意到小时数和秒数有效,但分钟数固定为6。有人对发生的事情有任何想法吗?

'm' is a representation of month, not minutes using the PHP date() function. “ m”表示月份,而不是使用PHP date()函数的分钟。 So, you are getting the '06', meaning June, not 06 minutes past 9. 因此,您得到的是“ 06”,表示6月,而不是9点的06分钟。

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 http://us2.php.net/manual/zh/function.date.php

m - Numeric representation of a month, with leading zeros m-一个月的数字表示,前导零

我认为分钟arg应该是i (小写字母),而不是m

使用它代替( i代替m ):

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

大写的m是月份,现在是六月;)分钟是“ i”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM