日期格式更正

时间:2012-03-13 10:33:43

标签: php

我想从以下位置更改此日期格式的外观:

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 } ?> 

3 个答案:

答案 0 :(得分:1)

$date = new DateTime('2012-01-01');
echo $date->format('d F Y');

PHP Date Function

编辑

<?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 } ?> 
  • d = 01至31
  • F = 1月到12月
  • Y = 1999或2003

答案 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)); 

?>