在PHP中格式化MySQL日期 [英] Format a MySQL date in PHP

查看:158
本文介绍了在PHP中格式化MySQL日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格类型为 datetime 中的列。我想以特定格式显示它们,所以我尝试使用这个:

I have a column in my table of type datetime. I want to display them in a particular format, so I tried using this:

echo date( 'm/d/Y - g:h A', strtotime($dateFromMySQL) );

...这完全是把所有东西弄乱了。

...which just messes everything up, completely.

如果我只是做 echo $ dateFromMySQL; (在一个循环中),我得到这个:

If I simply do echo $dateFromMySQL; (in a loop), I get this:


2011-09-10 01:03:04

2011-09-10 00:52:47

2011-09-10 00:40:26

等等...

2011-09-10 01:03:04
2011-09-10 00:52:47
2011-09-10 00:40:26
and so on...

。这是正确的。

如果我做 echo strtotime($ dateFromMySQL) code>,我得到这个:

If I do echo strtotime($dateFromMySQL);, I get this:


1315630984

1315630367

1315629626 < br>
等等...

1315630984
1315630367
1315629626
and so on...

...这可能是正确的。我不知道。

...which might be correct. I wouldn't know.

然而,当我做 echo date('m / d / Y - g:h:s A',strtotime($ dateFromMySQL)); ,我得到这个:

However, when I do echo date( 'm/d/Y - g:h:s A', strtotime($dateFromMySQL) );, I get this:


09/10/2011 - 1:01:04 AM

09/10/2011 - 12:12:47 AM

09/10/2011 - 12:12: 26 AM

等等...

09/10/2011 - 1:01:04 AM
09/10/2011 - 12:12:47 AM
09/10/2011 - 12:12:26 AM
and so on...

...显然是错误的。

...which is obviously wrong.

所以,我的问题是,我做错了什么?

我是不正确地使用 strtotime date

So, my question is, what am I doing wrong?
Am I somehow not using strtotime and date correctly?

推荐答案

我想你在寻找 m / d / Y - g:i:s A

h - 小时

- 分钟

h - hour
i - minutes

这篇关于在PHP中格式化MySQL日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆