FROM_UNIXTIME()与UNIX_TIMESTAMP()

来自http://tunps.com/from_unixtime-unix_timestamp

from_unixtime是MYSQL里的时间函数
date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串
后面的 '%Y%m%d' 主要是将返回值格式化
例如:
mysql>SELECT FROM_UNIXTIME( 1195488000, '%Y%m%d' )
->20071120
mysql>SELECT FROM_UNIXTIME( 1195488000, '%Y年%m月%d' )
->2007年11月20
UNIX_TIMESTAMP()是与之相对正好相反的时间函数
例如:
mysql> SELECT UNIX_TIMESTAMP('2007-11-20') ;
->1195488000

SELECT FROM_UNIXTIME(topic_time,'%Y-%m-%d %H:%m:%s') as topic_time from phpbb_topics;

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>