将 UNIX 时间戳格式更改为数据库
我正在完成一个教程,可以在这里找到... http://www.elated.com/articles/cms-in-an-afternoon-php-mysql/
我在将正确的日期格式输入数据库时遇到问题。我已成功添加日期格式为“yy-mm-dd”的 JQuery UI 日历,但我想以“dd-mm-yy”格式添加日期
UNIX 时间戳似乎总是将年份放在第一位,例如。 2010-04-03
这是我的 PHP 中提取日期的一行代码...
$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";
这是添加日期的代码,这是重要的一点,因为大多数用户会更好地理解 dd-mm-yy 格式...
$sql = "INSERT INTO articles ( publicationDate, title, summary, content ) VALUES (FROM_UNIXTIME(:publicationDate), :title, :summary, :content )";
任何非常感谢您的帮助,因为即使在阅读了部分 PHP 手册之后,我还是不知所措。
非常感谢, 光盘
I am completing a tutorial which can be found here...http://www.elated.com/articles/cms-in-an-afternoon-php-mysql/
I am having problems getting the correct date format into the database. I have successfully add JQuery UI calendar with a format of dateformat: "yy-mm-dd" but I want to add the date in the format "dd-mm-yy"
The UNIX Timestamp always seems to put the year first eg. 2010-04-03
This is a line of code from my PHP extracting the date...
$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";
This is one adding the date which is the important bit as most of the users will understand the dd-mm-yy format better...
$sql = "INSERT INTO articles ( publicationDate, title, summary, content ) VALUES (FROM_UNIXTIME(:publicationDate), :title, :summary, :content )";
Any help greatly appreciated as I'm at a lose, even after reading part of the PHP Manual.
Many thanks,
CD
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那不是 unix 时间戳。这是一个普通的 MySQL 格式的日期/日期时间字段。 Unix 时间戳只是自 1970 年 1 月 1 日以来的秒数,看起来一点也不像格式化日期。例如,
如果您想更改 MySQL 中日期的格式,您可以使用
DATE_FORMAT()
函数That's not a unix timestamp. That's a normal MySQL-formatted date/datetime field. A Unix timestamp is just the number of seconds since Jan 1/1970, and looks nothing like a formatted date. e.g.
If you want to change the format the date comes out of MySQL in, you can use the
DATE_FORMAT()
function如果问题是存储的是 YY-MM-DD 而不是 DD-MM-YY,为什么不反转它呢?
If the issue is that YY-MM-DD is stored instead of DD-MM-YY, why not reverse it?