将 UNIX 时间戳格式更改为数据库

发布于 2024-12-13 03:35:00 字数 736 浏览 3 评论 0原文

我正在完成一个教程,可以在这里找到... 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜中书 2024-12-20 03:35:00

那不是 unix 时间戳。这是一个普通的 MySQL 格式的日期/日期时间字段。 Unix 时间戳只是自 1970 年 1 月 1 日以来的秒数,看起来一点也不像格式化日期。例如,

'2011-10-31 15:01:00' in mysql is 1320094860 in timestamp format

如果您想更改 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.

'2011-10-31 15:01:00' in mysql is 1320094860 in timestamp format

If you want to change the format the date comes out of MySQL in, you can use the DATE_FORMAT() function

世界如花海般美丽 2024-12-20 03:35:00

如果问题是存储的是 YY-MM-DD 而不是 DD-MM-YY,为什么不反转它呢?

list($yy, $mm, $dd) = explode("-", $datestring);
$ddmmyy = "$dd-$mm-$yy";

If the issue is that YY-MM-DD is stored instead of DD-MM-YY, why not reverse it?

list($yy, $mm, $dd) = explode("-", $datestring);
$ddmmyy = "$dd-$mm-$yy";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文