日期格式在PHP中更改为英国日期

时间:2013-11-30 02:14:13

标签: php html

嗨那些希望改变日期以英国格式显示的男女学生d / m / y代码可以在下面找到任何有关我如何做到这一点的想法吗?

<style>

</style>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
<?php
include 'db-connect.php'; 

$result = mysqli_query($con,"SELECT * FROM payments");

echo "
 <table border='0' align='center' text-align='left'>
<tr>
<th>Date To: <input></input></th>
<th>Date From: <input></input></th>
</tr>
</table>";

echo "<table border='0' align='center' text-align='left'>

<tr>
<th>Title:</th>
<th>Date:</th>
<th>Incoming:</th>
<th>Outgoing:</th>
<th>Notes:</th>
</tr>";

$totalIncoming = 0;
    $totalOutgoing = 0;
    while($row = mysqli_fetch_array($result))
      {
      $totalIncoming += $row['incoming'];
      $totalOutgoing += $row['outgoing'];


      echo "<tr>";
      echo "<td>" . $row['title'] . "</td>";
      echo "<td>" . $row['date'] . "</td>";
      echo "<td> £" . $row['incoming'] . "</td>";
    echo "<td> £" .  $row['outgoing'] . "</td>";
    echo "<td>" . $row['notes'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";
$profit = $totalIncoming - $totalOutgoing;
    echo "<div class='payment-total'><h1>Profit : £" . "$profit</h1></div>";


mysqli_close($con);
?>

我真的很喜欢任何可以指引我正确方向的人,或者通过给我一行代码来帮助我!提前谢谢!

2 个答案:

答案 0 :(得分:4)

我无法真正看到与代码中的日期格式有关的任何内容。

您目前从数据库获取的日期格式是什么?

如果是string,请查看如何将日期字符串转换为时间PHP strtotimePHP Date Function。这应该对你有帮助。

使用此功能:

$oldDate = "2003/03/24";
$newDate = date("d/m/Y", strtotime($oldDate));

这会输出24/03/2003

因此,在您的代码案例中,它将是这样的:

echo "<td>" . date("d/m/Y", strtotime($row['date'])) . "</td>";

答案 1 :(得分:0)

使用DateTime

<?php
$date = new DateTime($row['date']);
echo $date->format('d-m-Y');
?>