我想从以下位置更改此日期格式的外观:
2012-01-01
到
2012年1月1日
我的代码:
<?php foreach($funds as $fund) { ?>
<li><?php echo $fund['fund']; ?><span class="price"><div align="center" class="h1"><strong><br />
R<?php echo $fund['price']; ?></strong><br />as at <br />
<?php echo $fund['date']; ?></div></span></li>
<?php } ?>
答案 0 :(得分:1)
$date = new DateTime('2012-01-01');
echo $date->format('d F Y');
编辑
<?php foreach($funds as $fund) { ?>
$date = new DateTime($fund['date']);
<li>
<?php echo $fund['fund']; ?>
<span class="price">
<div align="center" class="h1"><br />
<strong>R<?php echo $fund['price']; ?></strong><br />
as at <br />
<?php echo $date->format('d F Y'); ?>
</div>
</span>
</li>
<?php } ?>
答案 1 :(得分:1)
尝试此查询
select date_format(dateField,'%d %M %Y') from tableName;
- 更新
$records=mysql_query("select fund,price,date_format(date, '%d %M %Y') as date_formatted from fund");
foreach( $records as $row)
{
echo $row['fund'];
echo $row['price'];
echo $row['date_formatted'];
}
答案 2 :(得分:-1)
参考此http://php.net/manual/en/function.date.php
<?php
$date = '2012-01-01';
echo date("j F Y" , strtotime($date));
?>