将mysql时间戳转换为实际日期和时间?
我将日期存储在 mysql 表中,它们设置为在每行中存储为当前时间戳,并存储如下:
2010-05-29 01:17:35
但我想做的是以某种方式使用 PHP 来分隔所有内容并创建一个更像这样的日期:
2010 年 5 月 29 日上午 1:17
任何人都可以至少指导我走上正确的道路吗?非常感谢任何帮助!
I have dates stored in a mysql table, they are set to store as CURRENT TIMESTAMP in each row and are stored as follows:
2010-05-29 01:17:35
but what i am trying to do is somehow use PHP to be able to seperate everything and create a date more like:
May 29 2010 1:17 AM
can anyone at least direct me in the right path that i should take. any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.date.php
您有两种解决方案:
strtotime()
将日期解析为时间戳,并date( )
将其重新格式化为字符串DateTime
类In PHP code, this would mean using :
或者:
`strtotime` + `date` is the solution you'll see used the most ; but it is not the best solution : with those, you'll work on UNIX Timestamps, which means a limited range of dates *(from 1970 to 2038, if using 32 bits integers)*.
另一方面,使用
DateTime
类,您可以工作的日期范围没有限制和。You have two solutions :
strtotime()
to parse the date to a timestamp, anddate()
to re-format it to a stringDateTime
classIn PHP code, this would mean using :
Or :
`strtotime` + `date` is the solution you'll see used the most ; but it is not the best solution : with those, you'll work on UNIX Timestamps, which means a limited range of dates *(from 1970 to 2038, if using 32 bits integers)*.
ON the other hand, using the
DateTime
class, there will be no limit to the range of dates you can work with.如果您的表中有一个
DATETIME
字段,并且您只需要日期字段,则:或:
其中
timestamp
是您的列名称。If you have a
DATETIME
field in your table and you only want the date field, then:or:
where
timestamp
is your column name.