如何将时间戳转换为MySQL [英] How to convert timestamp to date MySQL

查看:129
本文介绍了如何将时间戳转换为MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在YouTube上关于如何制作图片上传网站的指南,由phpacademy,伟大的指南。但是,我试图通过以人性化的方式展示它来扩展它。



目前, albums.timestamp UNIX_TIMESTAMP()保存在数据库中,并以 1348372089 为例。现在,如果我想将这些数字转换成一个日常时间,例如 23-09-2012 05:00 (欧洲标准),我该怎么办? / p>

我尝试过 DATE(albums.timestamp) CONVERT(albums.timestamp,120 ) unix_timestamp(albums.timestamp)以及 CAST(120 as albums.timestamp),但没有一个工作。

解决方案

使用FROM_UNIXTIME(str,format)。
http:/ /dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime



第二个参数将允许您按照您的喜好格式化日期字符串。



格式化字符:

http://dev.mysql.com/doc/refman/5.1/en/date-and -time-functions.html#function_date-format


I'm following a guide on YouTube on how to make an Image Uploading website, by phpacademy, great guide. However, I'm trying to extend it a bit by displaying it in a human-readable way.

At the moment the albums.timestamp is saved on the database as UNIX_TIMESTAMP() and results in 1348372089 for example. Now, if I want to convert these numbers into a regular date and time, such as 23-09-2012 05:00 (European standard), how should I proceed?

I have tried DATE(albums.timestamp) and CONVERT(albums.timestamp, 120), unix_timestamp(albums.timestamp) as well as CAST(120 as albums.timestamp), but none of them works.

解决方案

Use FROM_UNIXTIME(str,format). http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime

The second parameter will let you format the date string to your liking.

Formatting characters:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

这篇关于如何将时间戳转换为MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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