显示数据库中的日期 PHP

发布于 2024-09-30 16:32:45 字数 233 浏览 1 评论 0 原文

现在我正在数据库中以 date("Ymd") 格式存储日期,并将其存储在 日期列

现在,我已经从数据库中检索了它,但我如何显示它,

October 31st 2010

谢谢!

right now I'm storing a date in the database, in the format date("Y-m-d") and im storing it in date column.

Now, I've retrieved it from the database but how can i display it like

October 31st 2010

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

痴情 2024-10-07 16:32:46

使用 date_format

示例:date_format(somefield, '%d-%m-%Y, %h:%i %p')

Use date_format in your SQL query.

Example: date_format(somefield, '%d-%m-%Y, %h:%i %p')

随波逐流 2024-10-07 16:32:45

使用 时间戳 /en/function.strtotime.php" rel="nofollow">strtotime 并使用 strtotime 对其进行格式化。 date.php" rel="nofollow">日期

echo date('F jS Y', strtotime($databaseDate));

首选的方法应该是使用 DateTime 类:

date_default_timezone_set('Asia/Tokyo');

$date = new DateTime($databaseDate);
echo $date->format('F jS Y');

Convert the date to a timestamp using strtotime and format it using date.

echo date('F jS Y', strtotime($databaseDate));

The preferred way going forward should be the use of the DateTime class though:

date_default_timezone_set('Asia/Tokyo');

$date = new DateTime($databaseDate);
echo $date->format('F jS Y');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文