如何在 PHP 中更改日期格式?


是的,使用 date() 和 strtotime() 結合起來,可以更改 PHP 中的日期格式。假設我們的日期如下——

$dateValue = "2020-09-19";

使用 strtotime() 方法更改日期格式——

$modifiedDate= date("d-m-Y", strtotime($dateValue));  

例子

 即時演示

<!DOCTYPE html>
<html>
<body>
<?php
   $dateValue = "2020-09-19";
   echo "The original date format is=",$dateValue,"<br>";
   $modifiedDate= date("d-m-Y", strtotime($dateValue));  
   echo "The changed date format is= ".$modifiedDate;  
?>
</body>
</html>

輸出

將生成以下輸出

The original date format is=2020-09-19
The changed date format is= 19-09-2020

更新於:2020-10-13

83 次瀏覽

開啟您的 職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.