php中的日期格式更改为uk日期


date format change in php to uk date

嗨,想要更改日期以英国格式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);
?>

我真的很感谢任何能给我指明正确方向的人,或者给我一行代码来帮助我!提前感谢!

我在代码中看不到任何与日期格式有关的内容。。

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

如果它是一个字符串,那么看看如何将日期字符串转换为时间PHP strtotime和PHP日期函数。这应该对你有帮助。

使用此功能:

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

输出24/03/2003

所以在你的代码案例中,它应该是这样的:

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

使用DateTime类

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