【发布时间】:2011-02-25 16:23:45
【问题描述】:
我总是使用以下日期函数得到 2011 年 2 月 28 日:
$time = $row['time'];
$date = date("F t Y",$time);
2 月 28 日(显然)没有创建任何时间戳,但这里是其余代码:
$sql = "SELECT * FROM `posts` WHERE `approved`='1' ORDER BY time DESC";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
//Post//
$title = $row['title'];
$content = $row['content'];
$time = $row['time'];
$date = date("F t Y",$time);
$creatorid = $row['uid'];
$creator = username($creatorid);
echo "<div class=\"post\">
<h1>".$title."</h1>
<p class=\"entry\">".$content."</p>
<div class=\"byline\">
<p class=\"info\">
Posted ".$date." By ".$creator."
</p>
<p class=\"links\"><a href=\"#\">Read More</a> | <a href=\"#\">Comments</a></p>
</div>
</div>";
}
谢谢 卡梅伦
【问题讨论】:
-
“时间”字段包含什么? MySQL 时间戳,整数?
-
您查看过存储在数据库中的值吗?它们是什么?
-
我认为它们是unix时间戳,它们是这样称呼的吗?它们是使用 time() 函数生成的
-
我认为只需 date("F t Y") 就足够了。您不能在格式化的日期调用中混合日期戳
-
是的,time() 返回一个 unix 时间戳。如果您将该时间戳直接存储在 mysql 中的
int字段中,那么您也可以使用 mysql 为您进行日期转换:date_format(from_unixtime(time), '%M %j %Y'))
标签: php function variables date